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 committed Nov 7, 2022
1 parent bf808b3 commit a085e6c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
27 changes: 14 additions & 13 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.core.TypeErasure.ErasedValueType
import reporting.*

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

fun.tpe.widen match {
case tpe: ValueType =>
structuralCall(nme.selectDynamic, Nil).cast(tpe)

case tpe: MethodType =>
case tpe @ (_: MethodType | _: ErasedValueType) =>
def isDependentMethod(tpe: Type): Boolean = tpe match {
case tpe: MethodType =>
tpe.isParamDependent ||
Expand All @@ -239,6 +237,9 @@ trait Dynamic {
structuralCall(nme.applyDynamic, classOfs).cast(tpe.finalResultType)
}

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

// (@allanrenucci) I think everything below is dead code
case _: PolyType =>
fail("is polymorphic")
Expand Down
10 changes: 10 additions & 0 deletions tests/pos/i14340.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
object i14340 {
class Foo(val value: Int) extends AnyVal

class Container extends reflect.Selectable

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

println(cont.foo.value)
}

0 comments on commit a085e6c

Please sign in to comment.