Skip to content

Missing ParameterizedType for Option in LTS 3.3 #20263

Open
@jchyb

Description

@jchyb

Compiler version

3.3.0, 3.3.1, 3.3.3 (works correctly in 3.4.0 and 3.4.1)

Minimized code

class ClassWithOption {
  val a: Option[Int] = 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

In LTS:

private final scala.Option ClassWithOption.a parametrised false

In 3.4.0 and 3.4.1:

private final scala.Option ClassWithOption.a parametrised true

When using the CFR decompiler on ClassWIthOption I get:
In LTS:

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

public class ClassWithOption {
    private final Option a = None$.MODULE$;

    public Option<Object> a() {
        return this.a;
    }
}

In 3.4:

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

public class ClassWithOption {
    private final Option<Object> a = None$.MODULE$;

    public Option<Object> a() {
        return this.a;
    }
}

Expectation

I expect the behavior in 3.4.
Some libraries may use java reflection features which depend on the erased type parameter being there. I suspect overeager type parameter erasure was not intentional, which is why it came back in 3.4.

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