Skip to content

Missing ParameterisedType for inherited generics #20270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jchyb opened this issue Apr 26, 2024 · 0 comments
Open

Missing ParameterisedType for inherited generics #20270

jchyb opened this issue Apr 26, 2024 · 0 comments

Comments

@jchyb
Copy link
Contributor

jchyb commented Apr 26, 2024

Compiler version

3.3.0, 3.3.1, 3.3.3, 3.4.0, 3.4.1

Minimized code

class ClassWithOption extends WithMap {
  val optionInClass: Option[String] = None
}
trait WithMap {
  val optionInTrait: Option[String] = None
}

object Test {
  def main(args: Array[String]) =
    classOf[ClassWithOption].getDeclaredFields.foreach { field =>
      println(field.toString + " parametrised " + field.getGenericType.isInstanceOf[java.lang.reflect.ParameterizedType])
    }
}

Output

private scala.Option ClassWithOption.optionInTrait parametrised false
private final scala.Option ClassWithOption.optionInClass parametrised true

Decompiling ClassWithOption with CFR shows:

/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  scala.None$
 *  scala.Option
 *  scala.runtime.Statics
 */
import scala.None$;
import scala.Option;
import scala.runtime.Statics;

public class ClassWithOption
implements WithOption {
    private Option optionInTrait;
    private final Option<String> optionInClass;

    public ClassWithOption() {
        WithOption.$init$(this);
        this.optionInClass = None$.MODULE$;
        Statics.releaseFence();
    }

    public Option optionInTrait() {
        return this.optionInTrait;
    }

    @Override
    public void WithOption$_setter_$optionInTrait_$eq(Option x$0) {
        this.optionInTrait = x$0;
    }

    public Option<String> optionInClass() {
        return this.optionInClass;
    }
}

Expectation

private scala.Option ClassWithOption.optionInTrait parametrised true
private final scala.Option ClassWithOption.optionInClass parametrised true

Similarly to fields directly in classes, inherited fields should also retain parameterisation in class file for use in java reflection, for reasons mentioned here

@jchyb jchyb added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label area:backend area:erasure labels Apr 26, 2024
@Gedochao Gedochao removed the stat:needs triage Every issue needs to have an "area" and "itype" label label May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants