Skip to content

Commit 7848ef6

Browse files
authored
Merge pull request #3494 from dotty-staging/fix-#3488
Rework NamedTypes
2 parents f92f278 + 759af1e commit 7848ef6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+971
-814
lines changed

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,8 @@ object Trees {
8585
* which implements copy-on-write. Another use-case is in method interpolateAndAdapt in Typer,
8686
* where we overwrite with a simplified version of the type itself.
8787
*/
88-
private[dotc] def overwriteType(tpe: T) = {
89-
if (this.isInstanceOf[Template[_]])
90-
tpe match {
91-
case tpe: TermRef => assert(tpe.hasFixedSym , s"$this <--- $tpe")
92-
}
88+
private[dotc] def overwriteType(tpe: T) =
9389
myTpe = tpe
94-
}
9590

9691
/** The type of the tree. In case of an untyped tree,
9792
* an UnAssignedTypeException is thrown. (Overridden by empty trees)

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
382382
val targs = tp.argTypes
383383
val tycon = tp.typeConstructor
384384
New(tycon)
385-
.select(TermRef.withSym(tycon, constr))
385+
.select(TermRef(tycon, constr))
386386
.appliedToTypes(targs)
387387
.appliedToArgs(args)
388388
}
@@ -709,7 +709,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
709709
val tp =
710710
if (sym.isType) {
711711
assert(!sym.is(TypeParam))
712-
TypeRef(tree.tpe, sym.name.asTypeName)
712+
TypeRef(tree.tpe, sym.asType)
713713
}
714714
else
715715
TermRef(tree.tpe, sym.name.asTermName, sym.denot.asSeenFrom(tree.tpe))
@@ -718,8 +718,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
718718

719719
/** A select node with the given selector name and signature and a computed type */
720720
def selectWithSig(name: Name, sig: Signature)(implicit ctx: Context): Tree =
721-
untpd.SelectWithSig(tree, name, sig)
722-
.withType(TermRef(tree.tpe, name.asTermName.withSig(sig)))
721+
untpd.SelectWithSig(tree, name, sig).withType(tree.tpe.select(name.asTermName, sig))
723722

724723
/** A select node with selector name and signature taken from `sym`.
725724
* Note: Use this method instead of select(sym) if the referenced symbol
@@ -927,7 +926,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
927926
}
928927
else denot.asSingleDenotation.termRef
929928
val fun = receiver
930-
.select(TermRef.withSym(receiver.tpe, selected.termSymbol.asTerm))
929+
.select(TermRef(receiver.tpe, selected.termSymbol.asTerm))
931930
.appliedToTypes(targs)
932931

933932
def adaptLastArg(lastParam: Tree, expectedType: Type) = {

compiler/src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ object Contexts {
201201
def implicits: ContextualImplicits = {
202202
if (implicitsCache == null )
203203
implicitsCache = {
204-
val implicitRefs: List[TermRef] =
204+
val implicitRefs: List[ImplicitRef] =
205205
if (isClassDefContext)
206206
try owner.thisType.implicitMembers
207207
catch {

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ class Definitions {
210210
* members at runtime.
211211
*/
212212
lazy val ScalaShadowingPackageVal = ctx.requiredPackage(nme.scalaShadowing)
213-
lazy val ScalaShadowingPackageClass = ScalaShadowingPackageVal.moduleClass.asClass
213+
def ScalaShadowingPackageClass(implicit ctx: Context) = ScalaShadowingPackageVal.moduleClass.asClass
214214

215215
/** Note: We cannot have same named methods defined in Object and Any (and AnyVal, for that matter)
216216
* because after erasure the Any and AnyVal references get remapped to the Object methods
@@ -511,7 +511,6 @@ class Definitions {
511511
lazy val IndexOutOfBoundsException = ctx.requiredClass("java.lang.IndexOutOfBoundsException")
512512
lazy val ClassClass = ctx.requiredClass("java.lang.Class")
513513
lazy val BoxedNumberClass = ctx.requiredClass("java.lang.Number")
514-
lazy val ThrowableClass = ctx.requiredClass("java.lang.Throwable")
515514
lazy val ClassCastExceptionClass = ctx.requiredClass("java.lang.ClassCastException")
516515
lazy val ArithmeticExceptionClass = ctx.requiredClass("java.lang.ArithmeticException")
517516
lazy val ArithmeticExceptionClass_stringConstructor = ArithmeticExceptionClass.info.member(nme.CONSTRUCTOR).suchThat(_.info.firstParamTypes match {
@@ -526,6 +525,8 @@ class Definitions {
526525

527526
// in scalac modified to have Any as parent
528527

528+
lazy val ThrowableType: TypeRef = ctx.requiredClassRef("java.lang.Throwable")
529+
def ThrowableClass(implicit ctx: Context) = ThrowableType.symbol.asClass
529530
lazy val SerializableType: TypeRef = ctx.requiredClassRef("scala.Serializable")
530531
def SerializableClass(implicit ctx: Context) = SerializableType.symbol.asClass
531532
lazy val StringBuilderType: TypeRef = ctx.requiredClassRef("scala.collection.mutable.StringBuilder")
@@ -685,7 +686,6 @@ class Definitions {
685686
// Derived types
686687

687688
def RepeatedParamType = RepeatedParamClass.typeRef
688-
def ThrowableType = ThrowableClass.typeRef
689689

690690
def ClassType(arg: Type)(implicit ctx: Context) = {
691691
val ctype = ClassClass.typeRef
@@ -834,6 +834,9 @@ class Definitions {
834834
def isTupleClass(cls: Symbol) = isVarArityClass(cls, str.Tuple)
835835
def isProductClass(cls: Symbol) = isVarArityClass(cls, str.Product)
836836

837+
def isScalaShadowingPackageClass(cls: Symbol) =
838+
cls.name == tpnme.scalaShadowing && cls.owner == RootClass
839+
837840
/** Returns the erased class of the function class `cls`
838841
* - FunctionN for N > 22 becomes FunctionXXL
839842
* - FunctionN for 22 > N >= 0 remains as FunctionN

0 commit comments

Comments
 (0)