@@ -1233,7 +1233,10 @@ class Typer extends Namer
12331233 def caseRest (implicit ctx : Context ) = {
12341234 val pat1 = checkSimpleKinded(typedType(cdef.pat)(ctx.addMode(Mode .Pattern )))
12351235 val pat2 = indexPattern(cdef).transform(pat1)
1236- val body1 = typedType(cdef.body, pt)
1236+ var body1 = typedType(cdef.body, pt)
1237+ if ! body1.isType then
1238+ assert(ctx.reporter.errorsReported)
1239+ body1 = TypeTree (errorType(" <error: not a type>" , cdef.sourcePos))
12371240 assignType(cpy.CaseDef (cdef)(pat2, EmptyTree , body1), pat2, body1)
12381241 }
12391242 caseRest(ctx.fresh.setFreshGADTBounds.setNewScope)
@@ -1548,7 +1551,13 @@ class Typer extends Namer
15481551
15491552 def typedAlternative (tree : untpd.Alternative , pt : Type )(implicit ctx : Context ): Alternative = {
15501553 val nestedCtx = ctx.addMode(Mode .InPatternAlternative )
1554+ def ensureValueTypeOrWildcard (tree : Tree ) =
1555+ if tree.tpe.isValueTypeOrWildcard then tree
1556+ else
1557+ assert(ctx.reporter.errorsReported)
1558+ tree.withType(defn.AnyType )
15511559 val trees1 = tree.trees.mapconserve(typed(_, pt)(nestedCtx))
1560+ .mapconserve(ensureValueTypeOrWildcard)
15521561 assignType(cpy.Alternative (tree)(trees1), trees1)
15531562 }
15541563
@@ -1924,13 +1933,17 @@ class Typer extends Namer
19241933 val annot1 = typedExpr(tree.annot, defn.AnnotationClass .typeRef)
19251934 val arg1 = typed(tree.arg, pt)
19261935 if (ctx.mode is Mode .Type ) {
1927- val result = assignType(cpy.Annotated (tree)(arg1, annot1), arg1, annot1)
1928- result.tpe match {
1929- case AnnotatedType (rhs, Annotation .WithBounds (bounds)) =>
1930- if (! bounds.contains(rhs)) ctx.error(em " type $rhs outside bounds $bounds" , tree.sourcePos)
1931- case _ =>
1932- }
1933- result
1936+ if arg1.isType then
1937+ val result = assignType(cpy.Annotated (tree)(arg1, annot1), arg1, annot1)
1938+ result.tpe match {
1939+ case AnnotatedType (rhs, Annotation .WithBounds (bounds)) =>
1940+ if (! bounds.contains(rhs)) ctx.error(em " type $rhs outside bounds $bounds" , tree.sourcePos)
1941+ case _ =>
1942+ }
1943+ result
1944+ else
1945+ assert(ctx.reporter.errorsReported)
1946+ TypeTree (UnspecifiedErrorType )
19341947 }
19351948 else {
19361949 val arg2 = arg1 match {
0 commit comments