CraftTweaker

CraftTweaker

151M Downloads

int type not working in generic classes.

idcppl opened this issue · 3 comments

commented

Intro:

Can't use the type int in a generic class. Is related to the issue #1198

What you expected to happen:

To be able to pass int type through a generic class.

Script used:

public class Duad<A, B> {
    public var a as A : get;
    public var b as B : get;
    public this(a as A, b as B) {
        this.a = a;
        this.b = b;
    }
}

public function duadExample(name as string, age as int) as Duad<string, int> {
    return new Duad<string, int>(name, age);
}

var jimmy = duadExample("Jimmy", 19);

println(jimmy.a);

crafttweaker.log file:

https://gist.github.com/idcppl/b709413319fe5a27bb1969a73f369e48


Environment:

  • Minecraft Version: 1.16.5
  • Forge Version: 36.0.46
  • CraftTweaker Version: 7.1.0.246
  • Are you using a server: no
commented

This should be fixed by 27416a98de35773e46a22d42c7d861a4611caa44, which will be released next update.

commented

This is due to the current handling of generics 🤔
For now, make it an optional/nullable type like

public class Duad<A, B> {
    public var a as A : get;
    public var b as B : get;
    public this(a as A, b as B) {
        this.a = a;
        this.b = b;
    }
}

public function duadExample(name as string, age as int) as Duad<string, int?> {
    return new Duad<string, int?>(name, age);
}

var jimmy = duadExample("Jimmy", 19);

println(jimmy.a);
println(jimmy.b);
commented

Realized I made this issue in a version that older(Like 5 days old), and tested it with version 7.1.0.252. Which didn't change anything.