Skip to content

Commit bf490eb

Browse files
committed
Move more post-processing out from TypeAssigner#selectionType
1 parent 2763aba commit bf490eb

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

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

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -150,39 +150,32 @@ trait TypeAssigner {
150150
val name = tree.name
151151
val p = nme.primitive
152152
name match
153-
case p.arrayApply => return MethodType(defn.IntType :: Nil, arrayElemType)
154-
case p.arrayUpdate => return MethodType(defn.IntType :: arrayElemType :: Nil, defn.UnitType)
155-
case p.arrayLength => return MethodType(Nil, defn.IntType)
153+
case p.arrayApply => MethodType(defn.IntType :: Nil, arrayElemType)
154+
case p.arrayUpdate => MethodType(defn.IntType :: arrayElemType :: Nil, defn.UnitType)
155+
case p.arrayLength => MethodType(Nil, defn.IntType)
156156
// Note that we do not need to handle calls to Array[T]#clone() specially:
157157
// The JLS section 10.7 says "The return type of the clone method of an array type
158158
// T[] is T[]", but the actual return type at the bytecode level is Object which
159159
// is casted to T[] by javac. Since the return type of Array[T]#clone() is Array[T],
160160
// this is exactly what Erasure will do.
161161
case _ =>
162-
163-
val pre = maybeSkolemizePrefix(qualType, name)
164-
val mbr = qualType.findMember(name, pre)
165-
if (reallyExists(mbr))
166-
qualType.select(name, mbr)
167-
else if (qualType.isErroneous || name.toTermName == nme.ERROR)
168-
UnspecifiedErrorType
169-
else if couldInstantiateTypeVar(qualType) then
170-
// try again with more defined qualifier type
171-
selectionType(tree, qual1)
172-
else if (name == nme.CONSTRUCTOR)
173-
errorType(ex"$qualType does not have a constructor", tree.srcPos)
174-
else
175-
NoType
162+
val pre = maybeSkolemizePrefix(qualType, name)
163+
val mbr = qualType.findMember(name, pre)
164+
if reallyExists(mbr) then qualType.select(name, mbr)
165+
else if qualType.isErroneous || name.toTermName == nme.ERROR then UnspecifiedErrorType
166+
else NoType
176167
}
177168

178169
def importSuggestionAddendum(pt: Type)(using Context): String = ""
179170

180171
def notAMember(tree: untpd.Select, qual: Tree)(using Context): ErrorType =
181-
val kind = if tree.isType then "type" else "value"
182172
val qualType = qual.tpe.widenIfUnstable
173+
def kind = if tree.isType then "type" else "value"
183174
def addendum = err.selectErrorAddendum(tree, qual, qualType, importSuggestionAddendum)
184-
errorType(NotAMember(qualType, tree.name, kind, addendum), tree.srcPos)
185-
175+
val msg: Message =
176+
if tree.name == nme.CONSTRUCTOR then ex"$qualType does not have a constructor"
177+
else NotAMember(qualType, tree.name, kind, addendum)
178+
errorType(msg, tree.srcPos)
186179

187180
/** The type of the selection in `tree`, where `qual1` is the typed qualifier part.
188181
* The selection type is additionally checked for accessibility.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,9 @@ class Typer extends Namer
562562
if (tree.name.isTypeName) checkStable(qual.tpe, qual.srcPos, "type prefix")
563563
checkStableIdentPattern(select1, pt)
564564
ConstFold(select1)
565+
else if couldInstantiateTypeVar(qual.tpe.widen) then
566+
// try again with more defined qualifier type
567+
typedSelect(untpdSelect, pt, qual)
565568
else if qual.tpe.derivesFrom(defn.DynamicClass)
566569
&& tree.name.isTermName && !isDynamicExpansion(untpdSelect)
567570
then

0 commit comments

Comments
 (0)