@@ -141,7 +141,25 @@ trait TypeAssigner {
141
141
else if (! qualType.isInstanceOf [TermType ])
142
142
qualType = errorType(em " $qualType is illegal as a selection prefix " , qual1.srcPos)
143
143
144
+ def arrayElemType = qual1.tpe.widen match
145
+ case JavaArrayType (elemtp) => elemtp
146
+ case qualType =>
147
+ report.error(" Expected Array but was " + qualType.show, tree.srcPos)
148
+ defn.NothingType
149
+
144
150
val name = tree.name
151
+ val p = nme.primitive
152
+ 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 )
156
+ // Note that we do not need to handle calls to Array[T]#clone() specially:
157
+ // The JLS section 10.7 says "The return type of the clone method of an array type
158
+ // T[] is T[]", but the actual return type at the bytecode level is Object which
159
+ // is casted to T[] by javac. Since the return type of Array[T]#clone() is Array[T],
160
+ // this is exactly what Erasure will do.
161
+ case _ =>
162
+
145
163
val pre = maybeSkolemizePrefix(qualType, name)
146
164
val mbr = qualType.findMember(name, pre)
147
165
def isDynamicExpansion (tree : untpd.RefTree ): Boolean = {
@@ -165,15 +183,19 @@ trait TypeAssigner {
165
183
selectionType(tree, qual1)
166
184
else if (name == nme.CONSTRUCTOR )
167
185
errorType(ex " $qualType does not have a constructor " , tree.srcPos)
168
- else {
169
- val kind = if (name.isTypeName) " type" else " value"
170
- def addendum = err.selectErrorAddendum(tree, qual1, qualType, importSuggestionAddendum)
171
- errorType(NotAMember (qualType, name, kind, addendum), tree.srcPos)
172
- }
186
+ else
187
+ NoType
173
188
}
174
189
175
190
def importSuggestionAddendum (pt : Type )(using Context ): String = " "
176
191
192
+ def notAMember (tree : untpd.Select , qual : Tree )(using Context ): ErrorType =
193
+ val kind = if tree.isType then " type" else " value"
194
+ val qualType = qual.tpe.widenIfUnstable
195
+ def addendum = err.selectErrorAddendum(tree, qual, qualType, importSuggestionAddendum)
196
+ errorType(NotAMember (qualType, tree.name, kind, addendum), tree.srcPos)
197
+
198
+
177
199
/** The type of the selection in `tree`, where `qual1` is the typed qualifier part.
178
200
* The selection type is additionally checked for accessibility.
179
201
*/
@@ -189,32 +211,12 @@ trait TypeAssigner {
189
211
def assignType (tree : untpd.Ident , tp : Type )(using Context ): Ident =
190
212
tree.withType(tp)
191
213
192
- def assignType (tree : untpd.Select , qual : Tree )(using Context ): Select = {
193
- def qualType = qual.tpe.widen
194
- def arrayElemType = {
195
- qualType match {
196
- case JavaArrayType (elemtp) => elemtp
197
- case _ =>
198
- report.error(" Expected Array but was " + qualType.show, tree.srcPos)
199
- defn.NothingType
200
- }
201
- }
202
- val p = nme.primitive
203
- val tp = tree.name match {
204
- case p.arrayApply => MethodType (defn.IntType :: Nil , arrayElemType)
205
- case p.arrayUpdate => MethodType (defn.IntType :: arrayElemType :: Nil , defn.UnitType )
206
- case p.arrayLength => MethodType (Nil , defn.IntType )
207
-
208
- // Note that we do not need to handle calls to Array[T]#clone() specially:
209
- // The JLS section 10.7 says "The return type of the clone method of an array type
210
- // T[] is T[]", but the actual return type at the bytecode level is Object which
211
- // is casted to T[] by javac. Since the return type of Array[T]#clone() is Array[T],
212
- // this is exactly what Erasure will do.
213
-
214
- case _ => accessibleSelectionType(tree, qual)
215
- }
214
+ def assignType (tree : untpd.Select , tp : Type )(using Context ): Select =
216
215
ConstFold .Select (tree.withType(tp))
217
- }
216
+
217
+ def assignType (tree : untpd.Select , qual : Tree )(using Context ): Select =
218
+ val ownType = accessibleSelectionType(tree, qual).orElse(notAMember(tree, qual))
219
+ assignType(tree, ownType)
218
220
219
221
/** Normalize type T appearing in a new T by following eta expansions to
220
222
* avoid higher-kinded types.
0 commit comments