aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dotty/tools/dotc/ast/untpd.scala1
-rw-r--r--src/dotty/tools/dotc/parsing/Parsers.scala11
-rw-r--r--tests/neg/unboundWildcard.scala (renamed from tests/pending/neg/unboundWildcard.scala)1
3 files changed, 9 insertions, 4 deletions
diff --git a/src/dotty/tools/dotc/ast/untpd.scala b/src/dotty/tools/dotc/ast/untpd.scala
index 8400e9352..cef78c6e6 100644
--- a/src/dotty/tools/dotc/ast/untpd.scala
+++ b/src/dotty/tools/dotc/ast/untpd.scala
@@ -205,6 +205,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
def rootDot(name: Name) = Select(Ident(nme.ROOTPKG), name)
def scalaDot(name: Name) = Select(rootDot(nme.scala_), name)
def scalaUnit = scalaDot(tpnme.Unit)
+ def scalaAny = scalaDot(tpnme.Any)
def makeConstructor(tparams: List[TypeDef], vparamss: List[List[ValDef]], rhs: Tree = EmptyTree)(implicit ctx: Context): DefDef =
DefDef(nme.CONSTRUCTOR, tparams, vparamss, TypeTree(), rhs)
diff --git a/src/dotty/tools/dotc/parsing/Parsers.scala b/src/dotty/tools/dotc/parsing/Parsers.scala
index 12f629c57..edc9d3f66 100644
--- a/src/dotty/tools/dotc/parsing/Parsers.scala
+++ b/src/dotty/tools/dotc/parsing/Parsers.scala
@@ -648,12 +648,17 @@ object Parsers {
}
/* ------------- TYPES ------------------------------------------------------ */
- /** Same as [[typ]], but emits a syntax error if it returns a wildcard.
+ /** Same as [[typ]], but if this results in a wildcard it emits a syntax error and
+ * returns a tree for type `Any` instead.
*/
def toplevelTyp(): Tree = {
val t = typ()
- for (wildcardPos <- findWildcardType(t)) syntaxError("unbound wildcard type", wildcardPos)
- t
+ findWildcardType(t) match {
+ case Some(wildcardPos) =>
+ syntaxError("unbound wildcard type", wildcardPos)
+ scalaAny
+ case None => t
+ }
}
/** Type ::= FunArgTypes `=>' Type
diff --git a/tests/pending/neg/unboundWildcard.scala b/tests/neg/unboundWildcard.scala
index eeee04fde..b137c2664 100644
--- a/tests/pending/neg/unboundWildcard.scala
+++ b/tests/neg/unboundWildcard.scala
@@ -1,6 +1,5 @@
object unboundWildcard {
- // TODO: move this to tests/neg once it doesn't crash the compiler anymore
val wildcardVal: _ = 0 // error: unbound wildcard type
val annotated: _ @unchecked = 0 // error: unbound wildcard type