Skip to content

Commit 3179b03

Browse files
authored
Merge pull request #1450 from cswinter/elim-toplevel-typebound
Fix #1443: Replace toplevel TypeBounds with Any
2 parents 3265323 + b029894 commit 3179b03

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/dotty/tools/dotc/ast/untpd.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
205205
def rootDot(name: Name) = Select(Ident(nme.ROOTPKG), name)
206206
def scalaDot(name: Name) = Select(rootDot(nme.scala_), name)
207207
def scalaUnit = scalaDot(tpnme.Unit)
208+
def scalaAny = scalaDot(tpnme.Any)
208209

209210
def makeConstructor(tparams: List[TypeDef], vparamss: List[List[ValDef]], rhs: Tree = EmptyTree)(implicit ctx: Context): DefDef =
210211
DefDef(nme.CONSTRUCTOR, tparams, vparamss, TypeTree(), rhs)

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -648,12 +648,17 @@ 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+
scalaAny
660+
case None => t
661+
}
657662
}
658663

659664
/** 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)