@@ -14,6 +14,7 @@ import Decorators._
1414import Symbols ._ , SymUtils ._ , NameOps ._
1515import ContextFunctionResults .annotateContextResults
1616import config .Printers .typr
17+ import util .SrcPos
1718import reporting ._
1819
1920object PostTyper {
@@ -180,6 +181,13 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
180181 => Checking .checkAppliedTypesIn(tree)
181182 case _ =>
182183
184+ private def checkGoodBounds (tpe : Type , pos : SrcPos )(using Context ): Unit = tpe.dealias match
185+ case tpe : TypeRef =>
186+ checkGoodBounds(tpe.info, pos)
187+ case TypeBounds (lo, hi) if ! (lo <:< hi) =>
188+ report.error(i " type argument has unrealizable bounds $tpe" , pos)
189+ case _ =>
190+
183191 private def removeUnwantedAnnotations (sym : Symbol , metaAnnotSym : Symbol ,
184192 metaAnnotSymBackup : Symbol , keepIfNoRelevantAnnot : Boolean )(using Context ): Unit =
185193 def shouldKeep (annot : Annotation ): Boolean =
@@ -342,7 +350,9 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
342350 if tree.symbol.is(Inline ) then
343351 ctx.compilationUnit.needsInlining = true
344352 val tree1 @ TypeApply (fn, args) = normalizeTypeArgs(tree)
345- args.foreach(checkInferredWellFormed)
353+ for arg <- args do
354+ checkInferredWellFormed(arg)
355+ checkGoodBounds(arg.tpe, arg.srcPos)
346356 if (fn.symbol != defn.ChildAnnot .primaryConstructor)
347357 // Make an exception for ChildAnnot, which should really have AnyKind bounds
348358 Checking .checkBounds(args, fn.tpe.widen.asInstanceOf [PolyType ])
0 commit comments