Skip to content

Commit 2ea376b

Browse files
author
s.bazarsadaev
committed
Closes #14340
- add dynamic access to value classes field
1 parent bf808b3 commit 2ea376b

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

compiler/src/dotty/tools/dotc/typer/Dynamic.scala

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@ package dotty.tools
22
package dotc
33
package typer
44

5-
import dotty.tools.dotc.ast.Trees._
5+
import dotty.tools.dotc.ast.Trees.*
66
import dotty.tools.dotc.ast.tpd
77
import dotty.tools.dotc.ast.untpd
88
import dotty.tools.dotc.core.Constants.Constant
9-
import dotty.tools.dotc.core.Contexts._
9+
import dotty.tools.dotc.core.Contexts.*
1010
import dotty.tools.dotc.core.Names.{Name, TermName}
11-
import dotty.tools.dotc.core.StdNames._
12-
import dotty.tools.dotc.core.Types._
13-
import dotty.tools.dotc.core.Decorators._
11+
import dotty.tools.dotc.core.StdNames.*
12+
import dotty.tools.dotc.core.Types.*
13+
import dotty.tools.dotc.core.Decorators.*
1414
import dotty.tools.dotc.core.TypeErasure
15-
import util.Spans._
16-
import core.Symbols._
17-
import ErrorReporting._
18-
import reporting._
15+
import util.Spans.*
16+
import core.Symbols.*
17+
import ErrorReporting.*
18+
import dotty.tools.dotc.core.TypeErasure.ErasedValueType
19+
import reporting.*
1920

2021
object Dynamic {
2122
private def isDynamicMethod(name: Name): Boolean =
@@ -215,10 +216,7 @@ trait Dynamic {
215216
errorTree(tree, em"Structural access not allowed on method $name because it $reason")
216217

217218
fun.tpe.widen match {
218-
case tpe: ValueType =>
219-
structuralCall(nme.selectDynamic, Nil).cast(tpe)
220-
221-
case tpe: MethodType =>
219+
case tpe @ (_: MethodType | _: ErasedValueType) =>
222220
def isDependentMethod(tpe: Type): Boolean = tpe match {
223221
case tpe: MethodType =>
224222
tpe.isParamDependent ||
@@ -239,6 +237,9 @@ trait Dynamic {
239237
structuralCall(nme.applyDynamic, classOfs).cast(tpe.finalResultType)
240238
}
241239

240+
case tpe: ValueType =>
241+
structuralCall(nme.selectDynamic, Nil).cast(tpe)
242+
242243
// (@allanrenucci) I think everything below is dead code
243244
case _: PolyType =>
244245
fail("is polymorphic")

tests/pos/i14340.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
object kek {
2+
class Foo(val value: Int) extends AnyVal
3+
4+
class Container extends reflect.Selectable
5+
6+
val cont = new Container :
7+
val foo = new Foo(1)
8+
9+
println(cont.foo.value)
10+
}

0 commit comments

Comments
 (0)