@@ -142,6 +142,24 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
142142 tree
143143 }
144144
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+
145163 private def transformSelect (tree : Select , targs : List [Tree ])(implicit ctx : Context ): Tree = {
146164 val qual = tree.qualifier
147165 qual.symbol.moduleClass.denot match {
@@ -226,17 +244,26 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
226244 else dropInlines.transform(arg)))
227245 else
228246 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
230253 case Select (nu : New , nme.CONSTRUCTOR ) if isCheckable(nu) =>
231254 // need to check instantiability here, because the type of the New itself
232255 // might be a type constructor.
233256 Checking .checkInstantiable(tree.tpe, nu.posd)
234- withNoCheckNews(nu :: Nil )(super .transform(app) )
257+ withNoCheckNews(nu :: Nil )(app1 )
235258 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)
238264 case tree : TypeApply =>
239265 val tree1 @ TypeApply (fn, args) = normalizeTypeArgs(tree)
266+ args.foreach(checkInferredWellFormed)
240267 if (fn.symbol != defn.ChildAnnot .primaryConstructor)
241268 // Make an exception for ChildAnnot, which should really have AnyKind bounds
242269 Checking .checkBounds(args, fn.tpe.widen.asInstanceOf [PolyType ])
@@ -262,11 +289,11 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
262289 }
263290 case tree : ValDef =>
264291 val tree1 = cpy.ValDef (tree)(rhs = normalizeErasedRhs(tree.rhs, tree.symbol))
265- processMemberDef (super .transform(tree1))
292+ processValOrDefDef (super .transform(tree1))
266293 case tree : DefDef =>
267294 annotateContextResults(tree)
268295 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 ]))
270297 case tree : TypeDef =>
271298 val sym = tree.symbol
272299 if (sym.isClass)
@@ -304,9 +331,6 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
304331 Checking .checkRealizable(ref.tpe, ref.posd)
305332 super .transform(tree)
306333 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)
310334 tree.withType(
311335 tree.tpe match {
312336 case AnnotatedType (tpe, annot) => AnnotatedType (tpe, transformAnnot(annot))
0 commit comments