@@ -142,6 +142,24 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
142
142
tree
143
143
}
144
144
145
+ private def processValOrDefDef (tree : Tree )(using Context ): tree.type =
146
+ tree match
147
+ case tree : ValOrDefDef if ! tree.symbol.is(Synthetic ) =>
148
+ checkInferredWellFormed(tree.tpt)
149
+ case _ =>
150
+ processMemberDef(tree)
151
+
152
+ private def checkInferredWellFormed (tree : Tree )(using ctx : Context ): Unit = tree match
153
+ case tree : TypeTree
154
+ if tree.span.isZeroExtent
155
+ // don't check TypeTrees with non-zero extent;
156
+ // these are derived from explicit types
157
+ && ! ctx.reporter.errorsReported
158
+ // don't check if errors were already reported; this avoids follow-on errors
159
+ // for inferred types if explicit types are already ill-formed
160
+ => Checking .checkAppliedTypesIn(tree)
161
+ case _ =>
162
+
145
163
private def transformSelect (tree : Select , targs : List [Tree ])(implicit ctx : Context ): Tree = {
146
164
val qual = tree.qualifier
147
165
qual.symbol.moduleClass.denot match {
@@ -226,17 +244,26 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
226
244
else dropInlines.transform(arg)))
227
245
else
228
246
tree
229
- methPart(app) match {
247
+ def app1 =
248
+ // reverse order of transforming args and fun. This way, we get a chance to see other
249
+ // well-formedness errors before reporting errors in possible inferred type args of fun.
250
+ val args1 = transform(app.args)
251
+ cpy.Apply (app)(transform(app.fun), args1)
252
+ methPart(app) match
230
253
case Select (nu : New , nme.CONSTRUCTOR ) if isCheckable(nu) =>
231
254
// need to check instantiability here, because the type of the New itself
232
255
// might be a type constructor.
233
256
Checking .checkInstantiable(tree.tpe, nu.posd)
234
- withNoCheckNews(nu :: Nil )(super .transform(app) )
257
+ withNoCheckNews(nu :: Nil )(app1 )
235
258
case _ =>
236
- super .transform(app)
237
- }
259
+ app1
260
+ case UnApply (fun, implicits, patterns) =>
261
+ // Reverse transform order for the same reason as in `app1` above.
262
+ val patterns1 = transform(patterns)
263
+ cpy.UnApply (tree)(transform(fun), transform(implicits), patterns1)
238
264
case tree : TypeApply =>
239
265
val tree1 @ TypeApply (fn, args) = normalizeTypeArgs(tree)
266
+ args.foreach(checkInferredWellFormed)
240
267
if (fn.symbol != defn.ChildAnnot .primaryConstructor)
241
268
// Make an exception for ChildAnnot, which should really have AnyKind bounds
242
269
Checking .checkBounds(args, fn.tpe.widen.asInstanceOf [PolyType ])
@@ -262,11 +289,11 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
262
289
}
263
290
case tree : ValDef =>
264
291
val tree1 = cpy.ValDef (tree)(rhs = normalizeErasedRhs(tree.rhs, tree.symbol))
265
- processMemberDef (super .transform(tree1))
292
+ processValOrDefDef (super .transform(tree1))
266
293
case tree : DefDef =>
267
294
annotateContextResults(tree)
268
295
val tree1 = cpy.DefDef (tree)(rhs = normalizeErasedRhs(tree.rhs, tree.symbol))
269
- processMemberDef (superAcc.wrapDefDef(tree1)(super .transform(tree1).asInstanceOf [DefDef ]))
296
+ processValOrDefDef (superAcc.wrapDefDef(tree1)(super .transform(tree1).asInstanceOf [DefDef ]))
270
297
case tree : TypeDef =>
271
298
val sym = tree.symbol
272
299
if (sym.isClass)
@@ -304,9 +331,6 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
304
331
Checking .checkRealizable(ref.tpe, ref.posd)
305
332
super .transform(tree)
306
333
case tree : TypeTree =>
307
- if tree.span.isZeroExtent then
308
- // Don't check TypeTrees with non-zero extent; these are derived from explicit types
309
- Checking .checkAppliedTypesIn(tree)
310
334
tree.withType(
311
335
tree.tpe match {
312
336
case AnnotatedType (tpe, annot) => AnnotatedType (tpe, transformAnnot(annot))
0 commit comments