Skip to content

Commit f6f1731

Browse files
committed
Remove exception for SingletonTypes in typeSymbol
typeSymbol now follows underlying type for SingletonTypes, same as for other TypeProxys.
1 parent ec10c6b commit f6f1731

16 files changed

+31
-32
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
690690

691691
private def isSimpleThrowable(tp: Type)(using Context): Boolean = tp match {
692692
case tp @ TypeRef(pre, _) =>
693-
(pre == NoPrefix || pre.widen.typeSymbol.isStatic) &&
693+
(pre == NoPrefix || pre.typeSymbol.isStatic) &&
694694
(tp.symbol derivesFrom defn.ThrowableClass) && !tp.symbol.is(Trait)
695695
case _ =>
696696
false

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -998,11 +998,10 @@ class Definitions {
998998
FunctionType(args.length, isContextual, isErased).appliedTo(args ::: resultType :: Nil)
999999
def unapply(ft: Type)(using Context): Option[(List[Type], Type, Boolean, Boolean)] = {
10001000
val tsym = ft.typeSymbol
1001-
if (isFunctionClass(tsym)) {
1001+
if isFunctionClass(tsym) && ft.isRef(tsym) then
10021002
val targs = ft.dealias.argInfos
10031003
if (targs.isEmpty) None
10041004
else Some(targs.init, targs.last, tsym.name.isContextFunction, tsym.name.isErasedFunction)
1005-
}
10061005
else None
10071006
}
10081007
}
@@ -1379,15 +1378,16 @@ class Definitions {
13791378
/** Is `tp` (an alias) of either a scala.FunctionN or a scala.ContextFunctionN
13801379
* instance?
13811380
*/
1382-
def isNonRefinedFunction(tp: Type)(using Context): Boolean = {
1381+
def isNonRefinedFunction(tp: Type)(using Context): Boolean =
13831382
val arity = functionArity(tp)
13841383
val sym = tp.dealias.typeSymbol
13851384

1386-
arity >= 0 &&
1387-
isFunctionClass(sym) &&
1388-
tp.isRef(FunctionType(arity, sym.name.isContextFunction, sym.name.isErasedFunction).typeSymbol) &&
1389-
!tp.isInstanceOf[RefinedType]
1390-
}
1385+
arity >= 0
1386+
&& isFunctionClass(sym)
1387+
&& tp.isRef(
1388+
FunctionType(arity, sym.name.isContextFunction, sym.name.isErasedFunction).typeSymbol,
1389+
skipRefined = false)
1390+
end isNonRefinedFunction
13911391

13921392
/** Is `tp` a representation of a (possibly dependent) function type or an alias of such? */
13931393
def isFunctionType(tp: Type)(using Context): Boolean =
@@ -1460,9 +1460,9 @@ class Definitions {
14601460
if ctx.erasedTypes then
14611461
atPhase(erasurePhase)(unapply(tp))
14621462
else
1463-
val tp1 = tp.dealias
1464-
if isContextFunctionClass(tp1.typeSymbol) then
1465-
val args = asContextFunctionType(tp).dropDependentRefinement.argInfos
1463+
val tp1 = asContextFunctionType(tp)
1464+
if tp1.exists then
1465+
val args = tp1.dropDependentRefinement.argInfos
14661466
Some((args.init, args.last, tp1.typeSymbol.name.isErasedFunction))
14671467
else None
14681468

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ class TypeApplications(val self: Type) extends AnyVal {
445445
* otherwise return Nil.
446446
* Existential types in arguments are returned as TypeBounds instances.
447447
*/
448-
final def argInfos(using Context): List[Type] = self.stripTypeVar.stripAnnots match {
448+
final def argInfos(using Context): List[Type] = self.stripped match {
449449
case AppliedType(tycon, args) => args
450450
case _ => Nil
451451
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
310310
def compareThis = {
311311
val cls2 = tp2.cls
312312
tp1 match {
313-
case tp1: NamedType if cls2.is(Module) && cls2.eq(tp1.widen.typeSymbol) =>
313+
case tp1: NamedType if cls2.is(Module) && cls2.eq(tp1.typeSymbol) =>
314314
cls2.isStaticOwner ||
315315
recur(tp1.prefix, cls2.owner.thisType) ||
316316
secondTry
@@ -391,7 +391,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
391391
case tp1: ThisType =>
392392
val cls1 = tp1.cls
393393
tp2 match {
394-
case tp2: TermRef if cls1.is(Module) && cls1.eq(tp2.widen.typeSymbol) =>
394+
case tp2: TermRef if cls1.is(Module) && cls1.eq(tp2.typeSymbol) =>
395395
cls1.isStaticOwner ||
396396
recur(cls1.owner.thisType, tp2.prefix) ||
397397
thirdTry

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean
571571
/** The erasure of a function result type. */
572572
private def eraseResult(tp: Type)(using Context): Type = tp match {
573573
case tp: TypeRef =>
574-
val sym = tp.typeSymbol
574+
val sym = tp.symbol
575575
if (sym eq defn.UnitClass) sym.typeRef
576576
// For a value class V, "new V(x)" should have type V for type adaptation to work
577577
// correctly (see SIP-15 and [[Erasure.Boxing.adaptToType]]), so the return type of a

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,6 @@ object Types {
419419
@tailrec final def typeSymbol(using Context): Symbol = this match {
420420
case tp: TypeRef => tp.symbol
421421
case tp: ClassInfo => tp.cls
422-
case tp: SingletonType => NoSymbol
423422
case tp: TypeProxy => tp.underlying.typeSymbol
424423
case _: JavaArrayType => defn.ArrayClass
425424
case _ => NoSymbol
@@ -774,8 +773,8 @@ object Types {
774773
core.println(s"findMember exception for $this member $name, pre = $pre, recCount = $recCount")
775774

776775
def showPrefixSafely(pre: Type)(using Context): String = pre.stripTypeVar match {
777-
case pre: TermRef => i"${pre.termSymbol.name}."
778-
case pre: TypeRef => i"${pre.typeSymbol.name}#"
776+
case pre: TermRef => i"${pre.symbol.name}."
777+
case pre: TypeRef => i"${pre.symbol.name}#"
779778
case pre: TypeProxy => showPrefixSafely(pre.underlying)
780779
case _ => if (pre.typeSymbol.exists) i"${pre.typeSymbol.name}#" else "."
781780
}

compiler/src/dotty/tools/dotc/reporting/messages.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ import ast.tpd
283283

284284
class NotAMember(site: Type, val name: Name, selected: String, addendum: => String = "")(using Context)
285285
extends NotFoundMsg(NotAMemberID) {
286-
//println(i"site = $site, decls = ${site.decls}, source = ${site.widen.typeSymbol.sourceFile}") //DEBUG
286+
//println(i"site = $site, decls = ${site.decls}, source = ${site.typeSymbol.sourceFile}") //DEBUG
287287

288288
def msg = {
289289
import core.Flags._

compiler/src/dotty/tools/dotc/transform/ElimOpaque.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class ElimOpaque extends MiniPhase with DenotTransformer {
6666
if sym == defn.Any_== || sym == defn.Any_!= then
6767
tree match
6868
case Apply(Select(receiver, name: TermName), args)
69-
if atPhase(thisPhase)(receiver.tpe.widen.dealias.typeSymbol.isOpaqueAlias) =>
69+
if atPhase(thisPhase)(receiver.tpe.widenDealias.typeSymbol.isOpaqueAlias) =>
7070
applyOverloaded(receiver, name, args, Nil, defn.BooleanType)
7171
case _ =>
7272
tree

compiler/src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class Erasure extends Phase with DenotTransformer {
161161

162162
def assertErased(tp: Type, tree: tpd.Tree = tpd.EmptyTree)(using Context): Unit = {
163163
def isAllowed(cls: Symbol, sourceName: String) =
164-
tp.widen.typeSymbol == cls && ctx.compilationUnit.source.file.name == sourceName
164+
tp.typeSymbol == cls && ctx.compilationUnit.source.file.name == sourceName
165165
assert(isErasedType(tp) ||
166166
isAllowed(defn.ArrayClass, "Array.scala") ||
167167
isAllowed(defn.TupleClass, "Tuple.scala") ||
@@ -229,7 +229,7 @@ object Erasure {
229229
*/
230230
private def safelyRemovableUnboxArg(tree: Tree)(using Context): Tree = tree match {
231231
case Apply(fn, arg :: Nil)
232-
if isUnbox(fn.symbol) && defn.ScalaBoxedClasses().contains(arg.tpe.widen.typeSymbol) =>
232+
if isUnbox(fn.symbol) && defn.ScalaBoxedClasses().contains(arg.tpe.typeSymbol) =>
233233
arg
234234
case _ =>
235235
EmptyTree
@@ -640,7 +640,7 @@ object Erasure {
640640
if !sym.exists && tree.name == nme.apply then
641641
// PolyFunction apply Selects will not have a symbol, so deduce the owner
642642
// from the typed qual.
643-
val owner = qual1.tpe.widen.typeSymbol
643+
val owner = qual1.tpe.typeSymbol
644644
if defn.isFunctionClass(owner) then owner else NoSymbol
645645
else
646646
val owner = sym.maybeOwner

compiler/src/dotty/tools/dotc/transform/InterceptedMethods.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class InterceptedMethods extends MiniPhase {
4848

4949
// TODO: add missing cases from scalac
5050
private def poundPoundValue(tree: Tree)(using Context) = {
51-
val s = tree.tpe.widen.typeSymbol
51+
val s = tree.tpe.typeSymbol
5252

5353
def staticsCall(methodName: TermName): Tree =
5454
ref(defn.staticsMethodRef(methodName)).appliedTo(tree)

compiler/src/dotty/tools/dotc/transform/TryCatchPatterns.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class TryCatchPatterns extends MiniPhase {
7272

7373
private def isSimpleThrowable(tp: Type)(using Context): Boolean = tp.stripAnnots match {
7474
case tp @ TypeRef(pre, _) =>
75-
(pre == NoPrefix || pre.widen.typeSymbol.isStatic) && // Does not require outer class check
75+
(pre == NoPrefix || pre.typeSymbol.isStatic) && // Does not require outer class check
7676
!tp.symbol.is(Flags.Trait) && // Traits not supported by JVM
7777
tp.derivesFrom(defn.ThrowableClass)
7878
case tp: AppliedType =>

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ class SpaceEngine(using Context) extends SpaceLogic {
486486
case tp @ RefinedType(parent, _, _) =>
487487
erase(parent)
488488

489-
case tref: TypeRef if tref.typeSymbol.isPatternBound =>
489+
case tref: TypeRef if tref.symbol.isPatternBound =>
490490
if (inArray) tref.underlying else WildcardType
491491

492492
case _ => tp

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ object Applications {
116116
if (sel.exists) sel :: tupleSelectors(n + 1, tp) else Nil
117117
}
118118
def genTupleSelectors(n: Int, tp: Type): List[Type] = tp match {
119-
case tp: AppliedType if !defn.isTupleClass(tp.typeSymbol) && tp.derivesFrom(defn.PairClass) =>
119+
case tp: AppliedType if !defn.isTupleClass(tp.tycon.typeSymbol) && tp.derivesFrom(defn.PairClass) =>
120120
val List(head, tail) = tp.args
121121
head :: genTupleSelectors(n, tail)
122122
case _ => tupleSelectors(n, tp)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class ImportInfo(symf: Context ?=> Symbol,
186186
def featureImported(feature: TermName, owner: Symbol)(using Context): Boolean =
187187

188188
def compute =
189-
val isImportOwner = site.widen.typeSymbol.eq(owner)
189+
val isImportOwner = site.typeSymbol.eq(owner)
190190
if isImportOwner && forwardMapping.contains(feature) then true
191191
else if isImportOwner && excluded.contains(feature) then false
192192
else

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ trait QuotesAndSplices {
327327
val isFreshTypeBindings = freshTypeBindings.map(_.symbol).toSet
328328
val typeMap = new TypeMap() {
329329
def apply(tp: Type): Type = tp match {
330-
case tp: TypeRef if tp.typeSymbol.isTypeSplice =>
330+
case tp: TypeRef if tp.symbol.isTypeSplice =>
331331
val tp1 = tp.dealias
332332
if (isFreshTypeBindings(tp1.typeSymbol)) tp1
333333
else tp
@@ -408,7 +408,7 @@ trait QuotesAndSplices {
408408
class ReplaceBindings extends TypeMap() {
409409
override def apply(tp: Type): Type = tp match {
410410
case tp: TypeRef =>
411-
val tp1 = if (tp.typeSymbol.isTypeSplice) tp.dealias else tp
411+
val tp1 = if (tp.symbol.isTypeSplice) tp.dealias else tp
412412
mapOver(typeBindings.get(tp1.typeSymbol).fold(tp)(_.symbol.typeRef))
413413
case tp => mapOver(tp)
414414
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ class RefChecks extends MiniPhase { thisPhase =>
11661166
case _ => false
11671167
}
11681168
def underlyingClass(tp: Type): Symbol = {
1169-
val sym = tp.widen.typeSymbol
1169+
val sym = tp.typeSymbol
11701170
if (sym.isAbstractOrParamType) underlyingClass(sym.info.bounds.hi)
11711171
else sym
11721172
}

0 commit comments

Comments
 (0)