Skip to content

Commit 9917bf2

Browse files
s.bazarsadaevG1ng3r
s.bazarsadaev
authored andcommitted
Closes #14340
- add dynamic access to value classes field
1 parent bf808b3 commit 9917bf2

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

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

Lines changed: 14 additions & 9 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.transform.ValueClasses
19+
import reporting.*
1920

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

217218
fun.tpe.widen match {
219+
case tpe if ValueClasses.isDerivedValueClass(tpe.classSymbol) =>
220+
val scall = structuralCall(nme.selectDynamic, Nil).cast(ValueClasses.underlyingOfValueClass(tpe.classSymbol.asClass))
221+
New(tpe, scall :: Nil).cast(tpe)
222+
218223
case tpe: ValueType =>
219224
structuralCall(nme.selectDynamic, Nil).cast(tpe)
220225

tests/run/i14340.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1

tests/run/i14340.scala

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

0 commit comments

Comments
 (0)