Skip to content

Commit

Permalink
Closes #14340
Browse files Browse the repository at this point in the history
- add dynamic access to value classes field
  • Loading branch information
s.bazarsadaev authored and G1ng3r committed Nov 9, 2022
1 parent bf808b3 commit 9917bf2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
23 changes: 14 additions & 9 deletions compiler/src/dotty/tools/dotc/typer/Dynamic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ package dotty.tools
package dotc
package typer

import dotty.tools.dotc.ast.Trees._
import dotty.tools.dotc.ast.Trees.*
import dotty.tools.dotc.ast.tpd
import dotty.tools.dotc.ast.untpd
import dotty.tools.dotc.core.Constants.Constant
import dotty.tools.dotc.core.Contexts._
import dotty.tools.dotc.core.Contexts.*
import dotty.tools.dotc.core.Names.{Name, TermName}
import dotty.tools.dotc.core.StdNames._
import dotty.tools.dotc.core.Types._
import dotty.tools.dotc.core.Decorators._
import dotty.tools.dotc.core.StdNames.*
import dotty.tools.dotc.core.Types.*
import dotty.tools.dotc.core.Decorators.*
import dotty.tools.dotc.core.TypeErasure
import util.Spans._
import core.Symbols._
import ErrorReporting._
import reporting._
import util.Spans.*
import core.Symbols.*
import ErrorReporting.*
import dotty.tools.dotc.transform.ValueClasses
import reporting.*

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

fun.tpe.widen match {
case tpe if ValueClasses.isDerivedValueClass(tpe.classSymbol) =>
val scall = structuralCall(nme.selectDynamic, Nil).cast(ValueClasses.underlyingOfValueClass(tpe.classSymbol.asClass))
New(tpe, scall :: Nil).cast(tpe)

case tpe: ValueType =>
structuralCall(nme.selectDynamic, Nil).cast(tpe)

Expand Down
1 change: 1 addition & 0 deletions tests/run/i14340.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
9 changes: 9 additions & 0 deletions tests/run/i14340.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Foo(val value: Int) extends AnyVal

class Container extends reflect.Selectable

val cont = new Container :
val foo = new Foo(1)

@main def Test: Unit =
println(cont.foo.value)

0 comments on commit 9917bf2

Please sign in to comment.