Skip to content

Missing ParameterisedType for inherited generics #20270

Open
@jchyb

Description

@jchyb

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions