Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
tree.select(defn.Any_typeCast).appliedToType(AndType(tree.tpe, tpnn))

def unapply(tree: tpd.TypeApply)(using Context): Option[tpd.Tree] = tree match
case TypeApply(Select(qual: RefTree, nme.asInstanceOfPM), arg :: Nil) =>
case TypeApply(Select(qual: RefTree, _), arg :: Nil) if tree.symbol == defn.Any_typeCast =>
arg.tpe match
case AndType(ref, _) if qual.tpe eq ref => Some(qual)
case _ => None
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ class Definitions {
@tu lazy val Any_## : TermSymbol = enterMethod(AnyClass, nme.HASHHASH, ExprType(IntType), Final)
@tu lazy val Any_isInstanceOf: TermSymbol = enterT1ParameterlessMethod(AnyClass, nme.isInstanceOf_, _ => BooleanType, Final)
@tu lazy val Any_asInstanceOf: TermSymbol = enterT1ParameterlessMethod(AnyClass, nme.asInstanceOf_, _.paramRefs(0), Final)
@tu lazy val Any_typeTest: TermSymbol = enterT1ParameterlessMethod(AnyClass, nme.isInstanceOfPM, _ => BooleanType, Final | Synthetic | Artifact)
@tu lazy val Any_typeCast: TermSymbol = enterT1ParameterlessMethod(AnyClass, nme.asInstanceOfPM, _.paramRefs(0), Final | Synthetic | Artifact | StableRealizable)
@tu lazy val Any_typeTest: TermSymbol = enterT1ParameterlessMethod(AnyClass, NameKinds.IsInstanceOf, _ => BooleanType, Final | Synthetic | Artifact)
@tu lazy val Any_typeCast: TermSymbol = enterT1ParameterlessMethod(AnyClass, NameKinds.AsInstanceOf, _.paramRefs(0), Final | Synthetic | Artifact | StableRealizable)
// generated by pattern matcher and explicit nulls, eliminated by erasure

/** def getClass[A >: this.type](): Class[? <: A] */
Expand Down
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/core/NameKinds.scala
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,10 @@ object NameKinds {
val ImplMethName: SuffixNameKind = new SuffixNameKind(IMPLMETH, "$")
val AdaptedClosureName: SuffixNameKind = new SuffixNameKind(ADAPTEDCLOSURE, "$adapted") { override def definesNewName = true }

val InstanceOf: SuffixNameKind = new SuffixNameKind(INSTANCEOF, "InstanceOf$")
val IsInstanceOf: TermName = InstanceOf(nme.isInstanceOfPM)
val AsInstanceOf: TermName = InstanceOf(nme.asInstanceOfPM)

/** A name together with a signature. Used in Tasty trees. */
object SignedName extends NameKind(SIGNED) {

Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/NameTags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ object NameTags extends TastyFormat.NameTags {
case EXPANDED => "EXPANDED"
case EXPANDPREFIX => "EXPANDPREFIX"
case TRAITSETTER => "TRAITSETTER"
case INSTANCEOF => "INSTANCEOF"
case UNIQUE => "UNIQUE"
case DEFAULTGETTER => "DEFAULTGETTER"
case OUTERSELECT => "OUTERSELECT"
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/StdNames.scala
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ object StdNames {
val asType: N = "asType"
val asClass: N = "asClass"
val asInstanceOf_ : N = "asInstanceOf"
val asInstanceOfPM: N = "$asInstanceOf$"
val asInstanceOfPM: N = "$as"
val assert_ : N = "assert"
val assume_ : N = "assume"
val box: N = "box"
Expand Down Expand Up @@ -499,7 +499,7 @@ object StdNames {
val isDefined: N = "isDefined"
val isEmpty: N = "isEmpty"
val isInstanceOf_ : N = "isInstanceOf"
val isInstanceOfPM: N = "$isInstanceOf$"
val isInstanceOfPM: N = "$is"
val java: N = "java"
val key: N = "key"
val lang: N = "lang"
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/Splicer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ object Splicer {
assert(args.isEmpty)
interpretedStaticFieldAccess(fn.symbol)
else if (fn.qualifier.symbol.is(Module) && fn.qualifier.symbol.isStatic)
if (fn.name == nme.asInstanceOfPM)
if fn.name == NameKinds.AsInstanceOf then
interpretModuleAccess(fn.qualifier.symbol)
else {
val staticMethodCall = interpretedStaticMethodCall(fn.qualifier.symbol.moduleClass, fn.symbol)
Expand Down
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Dynamic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import dotty.tools.dotc.ast.untpd
import dotty.tools.dotc.core.Constants.Constant
import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.Names.{Name, TermName}
import dotty.tools.dotc.core.NameKinds
import dotty.tools.dotc.core.StdNames._
import dotty.tools.dotc.core.Types._
import dotty.tools.dotc.core.Decorators._
Expand All @@ -23,8 +24,8 @@ object Dynamic {
}

object DynamicUnapply {
def unapply(tree: tpd.Tree): Option[List[tpd.Tree]] = tree match
case TypeApply(Select(qual, name), _) if name == nme.asInstanceOfPM =>
def unapply(tree: tpd.Tree)(using Context): Option[List[tpd.Tree]] = tree match
case TypeApply(Select(qual, _), _) if tree.symbol == defn.Any_typeCast =>
unapply(qual)
case Apply(Apply(Select(selectable, fname), Literal(Constant(name)) :: ctag :: Nil), _ :: implicits)
if fname == nme.applyDynamic && (name == "unapply" || name == "unapplySeq") =>
Expand Down
2 changes: 2 additions & 0 deletions tasty/src/dotty/tools/tasty/TastyFormat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ object TastyFormat {
final val EXPANDPREFIX = 4 // An expansion prefix `<prefix>$<suffix>`,
// used by Scala-2 for private names.

final val INSTANCEOF = 7 // Type test of cast on Any `$isInsctanceOf$` and `$asInsctanceOf$`

final val UNIQUE = 10 // A unique name `<name>$<num>` where `<num>`
// is used only once for each `<name>`.

Expand Down
8 changes: 8 additions & 0 deletions tests/neg/i8869.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- [E008] Not Found Error: tests/neg/i8869.scala:1:15 ------------------------------------------------------------------
1 |val test1 = "".$asInstanceOf$[Int] // error
| ^^^^^^^^^^^^^^^^^
| value $asInstanceOf$ is not a member of String - did you mean ("" : String).asInstanceOf?
-- [E008] Not Found Error: tests/neg/i8869.scala:2:15 ------------------------------------------------------------------
2 |val test2 = "".$isInstanceOf$[Int] // error
| ^^^^^^^^^^^^^^^^^
| value $isInstanceOf$ is not a member of String - did you mean ("" : String).isInstanceOf?
2 changes: 2 additions & 0 deletions tests/neg/i8869.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
val test1 = "".$asInstanceOf$[Int] // error
val test2 = "".$isInstanceOf$[Int] // error