Skip to content

Commit 72a8584

Browse files
committed
Fix #7818: Survive bad annotated types
1 parent 4885463 commit 72a8584

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,13 +1931,17 @@ class Typer extends Namer
19311931
val annot1 = typedExpr(tree.annot, defn.AnnotationClass.typeRef)
19321932
val arg1 = typed(tree.arg, pt)
19331933
if (ctx.mode is Mode.Type) {
1934-
val result = assignType(cpy.Annotated(tree)(arg1, annot1), arg1, annot1)
1935-
result.tpe match {
1936-
case AnnotatedType(rhs, Annotation.WithBounds(bounds)) =>
1937-
if (!bounds.contains(rhs)) ctx.error(em"type $rhs outside bounds $bounds", tree.sourcePos)
1938-
case _ =>
1939-
}
1940-
result
1934+
if arg1.isType then
1935+
val result = assignType(cpy.Annotated(tree)(arg1, annot1), arg1, annot1)
1936+
result.tpe match {
1937+
case AnnotatedType(rhs, Annotation.WithBounds(bounds)) =>
1938+
if (!bounds.contains(rhs)) ctx.error(em"type $rhs outside bounds $bounds", tree.sourcePos)
1939+
case _ =>
1940+
}
1941+
result
1942+
else
1943+
assert(ctx.reporter.errorsReported)
1944+
TypeTree(UnspecifiedErrorType)
19411945
}
19421946
else {
19431947
val arg2 = arg1 match {

tests/neg/i7818.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def foo = (x: @) => () // error

0 commit comments

Comments
 (0)