Skip to content

Applications of abstract higher-kinded types to wildcard arguments aren't rejected #4382

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
Blaisorblade opened this issue Apr 25, 2018 · 4 comments

Comments

@Blaisorblade
Copy link
Contributor

Carved out of #4375. The following code compiles, while I expect all the errors described—they're necessary if we want to ensure people can't write existentials (and otherwise, not sure what the current check is for). Such an error is useful for people who might not realize their types mean something else now.

The check for unreducibility seems simply incomplete:

object App {
  type Id[A] >: A <: A
  def v1: Id[_] = ??? // should give error

  type HkL[A] >: A
  def v2: HkL[_] = ??? // should give error

  type HkU[A] <: A
  def v3: HkU[_] = ???  // should give error

  type HkAbs[A]
  def v4: HkAbs[_] = ??? // should give error
}

contrast with

scala> def v: _ = ???
1 |def v: _ = ???
  |       ^
  |       Unbound wildcard type

To demonstrate this is a problem, let's use a trait instead:

trait Foo {
  type HkP[A] >: (A, A) <: (A, A)
  def v1: HkP[_] = ??? // should give error

  type HkL[A] >: (A, A)
  def v2: HkL[_] = ??? // should give error

  type HkU[A] <: (A, A)
  def v3: HkU[_] = ???  // should give error

  type HkAbs[A]
  def v4: HkAbs[_] = ??? // should give error
}
object Bar extends Foo {
  type HkP[A] = (A, A)
  type HkL[A] = (A, A)
  type HkU[A] = (A, A)
  type HkAbs[A] = (A, A)
}

Then at least the types are approximates without crashes (here):

scala> def foo = Bar.v1
def foo: (_, _)
@smarter
Copy link
Member

smarter commented Apr 26, 2018

See #4376 for an example that crashes the compiler because we assume that hk types do not have wildcard arguments.

@odersky odersky closed this as completed in 1d04427 May 1, 2018
odersky added a commit that referenced this issue May 1, 2018
Fix #4382: Disallow wildcard arguments for higher-kinded types
@Blaisorblade
Copy link
Contributor Author

We still get the same crash from

trait x0[x0[_]] {
  (??? :x0[_]):x0[Int]
}

which has no syntax errors. If you rename x0's type argument to anything other than x0 everything works.

That's minimized from #4452's and #4389:

// From 09d8cdb2f7be2b81c318d338626268b7ec28ab12.scala <==
trait x0[x0[]] {
(x1:x0[_):x0[

@Blaisorblade Blaisorblade reopened this May 3, 2018
@Blaisorblade
Copy link
Contributor Author

More precisely, the full stack trace is a bit different later, but still the same idea:

Exception in thread "main" java.lang.ClassCastException: dotty.tools.dotc.core.Types$LambdaParam cannot be cast to dotty.tools.dotc.core.Symbols$Symbol
	at dotty.tools.dotc.core.TypeComparer.compareCaptured$1(TypeComparer.scala:891)
	at dotty.tools.dotc.core.TypeComparer.isSubArg$1(TypeComparer.scala:903)
	at dotty.tools.dotc.core.TypeComparer.isSubArgs(TypeComparer.scala:912)
	at dotty.tools.dotc.core.TypeComparer.isMatchingApply$1(TypeComparer.scala:692)
	at dotty.tools.dotc.core.TypeComparer.compareAppliedType2$1(TypeComparer.scala:796)
	at dotty.tools.dotc.core.TypeComparer.thirdTry$1(TypeComparer.scala:405)
	at dotty.tools.dotc.core.TypeComparer.secondTry$1(TypeComparer.scala:363)
	at dotty.tools.dotc.core.TypeComparer.firstTry$1(TypeComparer.scala:285)
	at dotty.tools.dotc.core.TypeComparer.$anonfun$recur$2(TypeComparer.scala:860)
	at scala.runtime.java8.JFunction0$mcZ$sp.apply(JFunction0$mcZ$sp.java:12)
	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.reporting.trace$.apply(trace.scala:39)
	at dotty.tools.dotc.core.TypeComparer.recur(TypeComparer.scala:129)
	at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:124)
	at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:127)
	at dotty.tools.dotc.core.TypeComparer.topLevelSubType(TypeComparer.scala:110)
	at dotty.tools.dotc.core.Types$Type.$anonfun$$less$colon$less$1(Types.scala:778)
	at scala.runtime.java8.JFunction0$mcZ$sp.apply(JFunction0$mcZ$sp.java:12)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
	at dotty.tools.dotc.core.Types$Type.$less$colon$less(Types.scala:778)
	at dotty.tools.dotc.typer.Typer.adaptNoArgsOther$1(Typer.scala:2326)
	at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:2394)
	at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:2526)
	at dotty.tools.dotc.typer.Typer.$anonfun$adapt$1(Typer.scala:2071)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
	at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:2066)
	at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1856)
	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:1852)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1864)
	at dotty.tools.dotc.typer.Typer.ascription$1(Typer.scala:560)
	at dotty.tools.dotc.typer.Typer.$anonfun$typedTyped$5(Typer.scala:578)
	at dotty.tools.dotc.typer.Typer.cases$1(Typer.scala:550)
	at dotty.tools.dotc.typer.Typer.$anonfun$typedTyped$1(Typer.scala:576)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
	at dotty.tools.dotc.typer.Typer.typedTyped(Typer.scala:536)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1778)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1825)
	at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1856)
	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:1852)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1864)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1900)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1912)
	at dotty.tools.dotc.typer.Typer.$anonfun$typedClassDef$1(Typer.scala:1526)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:1450)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1765)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1824)
	at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1856)
	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:1852)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1864)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1883)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1912)
	at dotty.tools.dotc.typer.Typer.$anonfun$typedPackageDef$1(Typer.scala:1631)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:1624)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1804)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1825)
	at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1856)
	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:1852)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1864)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1924)
	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)

@Blaisorblade
Copy link
Contributor Author

Blaisorblade commented May 11, 2018

EDIT: moved comment to #4376.

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

2 participants