Skip to content

Setters for variables in refinements not working #13703

Closed
@prolativ

Description

@prolativ

Compiler version

3.1.0-RC3

Minimized code

trait Foo extends reflect.Selectable

@main def test: Unit =
  val f = new Foo { var i: Int = 0 }
  f.i = 1

Output

[error] (run-main-3) java.lang.NoSuchMethodException: test$package$$anon$1.i_=(int)
[error] java.lang.NoSuchMethodException: test$package$$anon$1.i_=(int)
[error]         at java.lang.Class.getMethod(Class.java:1786)
[error]         at scala.reflect.Selectable.applyDynamic(Selectable.scala:38)
[error]         at scala.reflect.Selectable.applyDynamic$(Selectable.scala:11)
[error]         at test$package$$anon$1.applyDynamic(test.scala:4)
[error]         at test$package$.test(test.scala:5)
[error]         at test.main(test.scala:3)
[error]         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[error]         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[error]         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[error]         at java.lang.reflect.Method.invoke(Method.java:498)

Expectation

I'm not really sure what is the expected level of support for variables inside refinements.
Currently trying to explicitly define a refined type with a variable member results in a compilation error

type F = Foo { var i: Int }
refinement cannot be `mutable`

If this is so by design we should disallow creating instances of subtypes of Selectable with variable members.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions