Skip to content

Commit c201dec

Browse files
committed
Fix scala#1443: Replace toplevel TypeBounds with Any
1 parent 62348de commit c201dec

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -648,12 +648,18 @@ object Parsers {
648648
}
649649

650650
/* ------------- TYPES ------------------------------------------------------ */
651-
/** Same as [[typ]], but emits a syntax error if it returns a wildcard.
651+
/** Same as [[typ]], but if this results in a wildcard it emits a syntax error and
652+
* returns a tree for type `Any` instead.
652653
*/
653654
def toplevelTyp(): Tree = {
654655
val t = typ()
655-
for (wildcardPos <- findWildcardType(t)) syntaxError("unbound wildcard type", wildcardPos)
656-
t
656+
findWildcardType(t) match {
657+
case Some(wildcardPos) =>
658+
syntaxError("unbound wildcard type", wildcardPos)
659+
Select(Select(Ident(Names.termName("_root_")), Names.termName("scala")),
660+
Names.typeName("Any")).withPos(t.pos)
661+
case None => t
662+
}
657663
}
658664

659665
/** Type ::= FunArgTypes `=>' Type

tests/pending/neg/unboundWildcard.scala renamed to tests/neg/unboundWildcard.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
object unboundWildcard {
22

3-
// TODO: move this to tests/neg once it doesn't crash the compiler anymore
43
val wildcardVal: _ = 0 // error: unbound wildcard type
54

65
val annotated: _ @unchecked = 0 // error: unbound wildcard type

0 commit comments

Comments
 (0)