Skip to content

Parser should reject wildcards in invalid positions #4373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sir-wabbit opened this issue Apr 25, 2018 · 4 comments
Closed

Parser should reject wildcards in invalid positions #4373

sir-wabbit opened this issue Apr 25, 2018 · 4 comments

Comments

@sir-wabbit
Copy link

sir-wabbit commented Apr 25, 2018

Seems to be caused by wildcards in unions or intersections in type bounds.

class X[A >: _ | X[_]]
// or
class X[A >: _ | _]
// or
class X[A <: (Int & _)]
Exception in thread "main" java.lang.AssertionError: assertion failed: TypeBounds(TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Nothing),TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Any)) AppliedType(TypeRef(ThisType(TypeRef(ThisType(TypeRef(NoPrefix,module class <empty>)),module class App$)),class X),List(TypeBounds(TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Nothing),TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Any))))
	at scala.Predef$.assert(Predef.scala:219)
	at dotty.tools.dotc.core.Types$OrType.<init>(Types.scala:2523)
	at dotty.tools.dotc.core.Types$CachedOrType.<init>(Types.scala:2551)
	at dotty.tools.dotc.core.Types$OrType$.apply(Types.scala:2556)
	at dotty.tools.dotc.typer.TypeAssigner.assignType(TypeAssigner.scala:488)
	at dotty.tools.dotc.typer.TypeAssigner.assignType$(TypeAssigner.scala:487)
	at dotty.tools.dotc.typer.Typer.assignType(Typer.scala:83)
	at dotty.tools.dotc.typer.Typer.$anonfun$typedOrTypeTree$1(Typer.scala:1188)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
	at dotty.tools.dotc.typer.Typer.typedOrTypeTree(Typer.scala:1184)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1801)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1829)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1816)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1829)
	at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1860)
	at dotty.tools.dotc.reporting.trace$.op1$3(trace.scala:32)
	at dotty.tools.dotc.reporting.trace$.apply(trace.scala:33)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1856)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1868)
	at dotty.tools.dotc.typer.Typer.$anonfun$typedTypeBoundsTree$1(Typer.scala:1286)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
	at dotty.tools.dotc.typer.Typer.typedTypeBoundsTree(Typer.scala:1284)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1806)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1829)
	at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1860)
	at dotty.tools.dotc.reporting.trace$.op1$3(trace.scala:32)
	at dotty.tools.dotc.reporting.trace$.apply(trace.scala:33)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1856)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1868)
	at dotty.tools.dotc.typer.Namer.$anonfun$typedAheadType$1(Namer.scala:1006)
	at dotty.tools.dotc.typer.Namer.typedAheadImpl(Namer.scala:999)
	at dotty.tools.dotc.typer.Namer.typedAheadType(Namer.scala:1006)
	at dotty.tools.dotc.typer.Namer.typeDefSig(Namer.scala:1256)
	at dotty.tools.dotc.typer.Namer$TypeDefCompleter.typeSig(Namer.scala:878)
	at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:843)
	at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:821)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:248)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeInfo$1(SymDenotations.scala:211)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.info(SymDenotations.scala:213)
	at dotty.tools.dotc.ast.desugar$DerivedFromParamTree.derivedTree(Desugar.scala:98)
	at dotty.tools.dotc.ast.desugar$DerivedFromParamTree.derivedTree(Desugar.scala:51)
	at dotty.tools.dotc.typer.Typer.$anonfun$typedTypeTree$1(Typer.scala:1158)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
	at dotty.tools.dotc.typer.Typer.typedTypeTree(Typer.scala:1153)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1798)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1829)
	at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1860)
	at dotty.tools.dotc.reporting.trace$.op1$3(trace.scala:32)
	at dotty.tools.dotc.reporting.trace$.apply(trace.scala:33)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1856)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1868)
	at dotty.tools.dotc.typer.Namer.$anonfun$typedAheadType$1(Namer.scala:1006)
	at dotty.tools.dotc.typer.Namer.typedAheadImpl(Namer.scala:999)
	at dotty.tools.dotc.typer.Namer.typedAheadType(Namer.scala:1006)
	at dotty.tools.dotc.typer.Namer.typeDefSig(Namer.scala:1256)
	at dotty.tools.dotc.typer.Namer$TypeDefCompleter.typeSig(Namer.scala:878)
	at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:843)
	at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:821)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:248)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeInfo$1(SymDenotations.scala:211)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.info(SymDenotations.scala:213)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:354)
	at dotty.tools.dotc.typer.Namer.$anonfun$defDefSig$1(Namer.scala:1217)
	at dotty.tools.dotc.typer.Namer.$anonfun$defDefSig$1$adapted(Namer.scala:1217)
	at scala.collection.immutable.List.foreach(List.scala:389)
	at dotty.tools.dotc.typer.Namer.defDefSig(Namer.scala:1217)
	at dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:796)
	at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:843)
	at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:821)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:248)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeInfo$1(SymDenotations.scala:211)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.info(SymDenotations.scala:213)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:354)
	at dotty.tools.dotc.typer.Namer$ClassCompleter.completeInCreationContext(Namer.scala:979)
	at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:821)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:248)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeInfo$1(SymDenotations.scala:211)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.info(SymDenotations.scala:213)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:354)
	at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:1730)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1755)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1828)
	at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1860)
	at dotty.tools.dotc.reporting.trace$.op1$3(trace.scala:32)
	at dotty.tools.dotc.reporting.trace$.apply(trace.scala:33)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1856)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1868)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1887)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1916)
	at dotty.tools.dotc.typer.Typer.$anonfun$typedClassDef$1(Typer.scala:1529)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:1455)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1768)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1828)
	at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1860)
	at dotty.tools.dotc.reporting.trace$.op1$3(trace.scala:32)
	at dotty.tools.dotc.reporting.trace$.apply(trace.scala:33)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1856)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1868)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1887)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1916)
	at dotty.tools.dotc.typer.Typer.$anonfun$typedPackageDef$1(Typer.scala:1636)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:1627)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1808)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1829)
	at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1860)
	at dotty.tools.dotc.reporting.trace$.op1$3(trace.scala:32)
	at dotty.tools.dotc.reporting.trace$.apply(trace.scala:33)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1856)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1868)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1928)
	at dotty.tools.dotc.typer.FrontEnd.$anonfun$typeCheck$1(FrontEnd.scala:66)
	at dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:34)
	at dotty.tools.dotc.typer.FrontEnd.typeCheck(FrontEnd.scala:64)
	at dotty.tools.dotc.typer.FrontEnd.$anonfun$runOn$7(FrontEnd.scala:95)
	at dotty.tools.dotc.typer.FrontEnd.$anonfun$runOn$7$adapted(FrontEnd.scala:95)
	at scala.collection.immutable.List.foreach(List.scala:389)
	at dotty.tools.dotc.typer.FrontEnd.runOn(FrontEnd.scala:95)
	at dotty.tools.dotc.Run.$anonfun$compileUnits$3(Run.scala:174)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.util.Stats$.trackTime(Stats.scala:47)
	at dotty.tools.dotc.Run.$anonfun$compileUnits$2(Run.scala:171)
	at dotty.tools.dotc.Run.$anonfun$compileUnits$2$adapted(Run.scala:169)
	at scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:32)
	at scala.collection.IndexedSeqOptimized.foreach$(IndexedSeqOptimized.scala:29)
	at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:191)
	at dotty.tools.dotc.Run.runPhases$1(Run.scala:169)
	at dotty.tools.dotc.Run.$anonfun$compileUnits$1(Run.scala:194)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:88)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:149)
	at dotty.tools.dotc.Run.compileSources(Run.scala:136)
	at dotty.tools.dotc.Run.compile(Run.scala:120)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:29)
	at dotty.tools.dotc.Driver.process(Driver.scala:127)
	at dotty.tools.dotc.Driver.process(Driver.scala:96)
	at dotty.tools.dotc.Driver.process(Driver.scala:108)
	at dotty.tools.dotc.Driver.main(Driver.scala:135)
	at dotty.tools.dotc.Main.main(Main.scala)
@biboudis biboudis changed the title AssertionError AssertionError using wildcards in unions or intersections in type bounds Apr 25, 2018
@smarter
Copy link
Member

smarter commented Apr 26, 2018

The parser is already responsible for rejecting:

class Foo[X <: _]

I think it should also be able to reject your examples. Here's a few more:

class A1 extends _

object Test {
  type T1 = _
  type T2 = _[Int]
  type T3 = _ { type S }
  type T4 = [X] => _
}

@smarter smarter changed the title AssertionError using wildcards in unions or intersections in type bounds Parser should reject wildcards in invalid positions Apr 26, 2018
@Blaisorblade Blaisorblade self-assigned this Apr 26, 2018
@Blaisorblade
Copy link
Contributor

I can give this a try, it's a good exercise. (Whether I can do it timely is a different question.)

@Blaisorblade
Copy link
Contributor

I guess the plan is to fix the parser by extending the existing strategy, that is carefully thread wildOk and choose between typ() and toplevelTyp()?

@smarter
Copy link
Member

smarter commented Apr 28, 2018

I don't think any of the problematic case are context dependent so no need to pass a parameter around, just check that there is no wildcard when parsing the type trees where wildcards should not be allowed.

Blaisorblade added a commit to dotty-staging/dotty that referenced this issue Apr 30, 2018
Fix scala#4373.

The testcase is from examples in scala#4373, variations and tests for types
with wildcards. I'm unsure for a couple cases.
Blaisorblade added a commit to dotty-staging/dotty that referenced this issue Apr 30, 2018
Fix scala#4373.

The testcase is from examples in scala#4373, variations and tests for types
with wildcards. I'm unsure for a couple cases.
Blaisorblade added a commit to dotty-staging/dotty that referenced this issue May 1, 2018
Fix scala#4373.

The testcase is from examples in scala#4373, variations and tests for types
with wildcards.
Blaisorblade added a commit to dotty-staging/dotty that referenced this issue May 2, 2018
Fix scala#4373.

The testcase is from examples in scala#4373, variations and tests for types
with wildcards.
allanrenucci added a commit that referenced this issue May 7, 2018
Fix #4373: reject wildcard types in syntactically invalid positions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants