Skip to content

TypeApplications#noHK: return false for Nothing #966

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
wants to merge 1 commit into from

Conversation

smarter
Copy link
Member

@smarter smarter commented Nov 20, 2015

Otherwise, when a higher-kinded type variable is instantiated to Nothing,
we will try to eta-expand it and trigger an assertion in
Definitions#LambdaTrait.

Review by @odersky

@smarter
Copy link
Member Author

smarter commented Nov 20, 2015

Turns out this does not solve all issues with Nothing as a higher-kinded type, not sure what we should do here without adding even more special cases for Nothing:

object Test {
  def foo[M[_]]: M[Int] = ???
  val x = foo[Nothing]
}
% dotc -Xprint:frontend tests/pos/hk_nothing.scala
result of tests/pos/hk_nothing.scala after frontend:
package <empty> {
  final lazy module val Test: Test$ = new Test$()
  final module class Test$() extends Object() { this: Test.type => 
    def foo[M <: [hk$0] => ]: M[Int] = ???
    val x: Nothing{hk$0 = Int}#$apply = Test.foo[Nothing]
  }
}
dotty.tools.dotc.core.Types$MissingType: cannot resolve reference to type Nothing{hk$0 = Int}.$apply
the classfile defining the type might be missing from the classpath
        at dotty.tools.dotc.core.TypeErasure.dotty$tools$dotc$core$TypeErasure$$sigName(TypeErasure.scala:447)
        at dotty.tools.dotc.core.TypeErasure$.sigName(TypeErasure.scala:134)
        at dotty.tools.dotc.core.Signature$.apply(Signature.scala:76)
        at dotty.tools.dotc.core.Types$MethodicType$class.resultSignature(Types.scala:2047)
        at dotty.tools.dotc.core.Types$ExprType.resultSignature(Types.scala:2238)
        at dotty.tools.dotc.core.Types$ExprType.computeSignature(Types.scala:2242)
        at dotty.tools.dotc.core.Types$MethodicType$class.signature(Types.scala:2057)
        at dotty.tools.dotc.core.Types$ExprType.signature(Types.scala:2238)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.signature(Denotations.scala:460)
        at dotty.tools.dotc.core.SymDenotations$SymDenotation.termRefWithSig(SymDenotations.scala:1060)
        at dotty.tools.dotc.typer.TypeAssigner$class.assignType(TypeAssigner.scala:398)
        at dotty.tools.dotc.typer.Typer.assignType(Typer.scala:57)
        at dotty.tools.dotc.ast.tpd$.polyDefDef(tpd.scala:208)
        at dotty.tools.dotc.ast.tpd$.DefDef(tpd.scala:184)
        at dotty.tools.dotc.ast.tpd$.DefDef(tpd.scala:181)
        at dotty.tools.dotc.transform.Getters.transformValDef(Getters.scala:70)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer.goValDef(TreeTransform.scala:823)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer.transformNamed(TreeTransform.scala:994)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer$$anonfun$transform$2.apply(TreeTransform.scala:1212)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer$$anonfun$transform$2.apply(TreeTransform.scala:1205)
        at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:154)
        at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:53)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer.transform(TreeTransform.scala:1204)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer.dotty$tools$dotc$transform$TreeTransforms$TreeTransformer$$transformStat$1(TreeTransform.scala:1238)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer$$anonfun$38.apply(TreeTransform.scala:1242)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer$$anonfun$38.apply(TreeTransform.scala:1242)
        at dotty.tools.dotc.core.Decorators$ListDecorator$.loop$1(Decorators.scala:51)
        at dotty.tools.dotc.core.Decorators$ListDecorator$.mapconserve$extension(Decorators.scala:67)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer.transformStats(TreeTransform.scala:1242)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer.transformUnnamed(TreeTransform.scala:1183)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer$$anonfun$transform$2.apply(TreeTransform.scala:1213)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer$$anonfun$transform$2.apply(TreeTransform.scala:1205)
        at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:154)
        at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:53)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer.transform(TreeTransform.scala:1204)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer.transformNamed(TreeTransform.scala:1011)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer$$anonfun$transform$2.apply(TreeTransform.scala:1212)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer$$anonfun$transform$2.apply(TreeTransform.scala:1205)
        at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:154)
        at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:53)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer.transform(TreeTransform.scala:1204)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer.dotty$tools$dotc$transform$TreeTransforms$TreeTransformer$$transformStat$1(TreeTransform.scala:1238)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer$$anonfun$38.apply(TreeTransform.scala:1242)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer$$anonfun$38.apply(TreeTransform.scala:1242)
        at dotty.tools.dotc.core.Decorators$ListDecorator$.loop$1(Decorators.scala:51)
        at dotty.tools.dotc.core.Decorators$ListDecorator$.mapconserve$extension(Decorators.scala:67)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer.transformStats(TreeTransform.scala:1242)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer.transformUnnamed(TreeTransform.scala:1192)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer$$anonfun$transform$2.apply(TreeTransform.scala:1213)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer$$anonfun$transform$2.apply(TreeTransform.scala:1205)
        at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:154)
        at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:53)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer.transform(TreeTransform.scala:1204)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer.macroTransform(TreeTransform.scala:563)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer.run(TreeTransform.scala:480)
        at dotty.tools.dotc.core.Phases$Phase$$anonfun$runOn$1.apply(Phases.scala:271)
        at dotty.tools.dotc.core.Phases$Phase$$anonfun$runOn$1.apply(Phases.scala:269)
        at scala.collection.immutable.List.map(List.scala:273)
        at dotty.tools.dotc.core.Phases$Phase$class.runOn(Phases.scala:269)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer.runOn(TreeTransform.scala:474)
        at dotty.tools.dotc.Run$$anonfun$compileUnits$1$$anonfun$apply$mcV$sp$1.apply(Run.scala:60)
        at dotty.tools.dotc.Run$$anonfun$compileUnits$1$$anonfun$apply$mcV$sp$1.apply(Run.scala:57)
        at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
        at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:186)
        at dotty.tools.dotc.Run$$anonfun$compileUnits$1.apply$mcV$sp(Run.scala:57)
        at dotty.tools.dotc.Run$$anonfun$compileUnits$1.apply(Run.scala:52)
        at dotty.tools.dotc.Run$$anonfun$compileUnits$1.apply(Run.scala:52)
        at dotty.tools.dotc.util.Stats$.monitorHeartBeat(Stats.scala:69)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:52)
        at dotty.tools.dotc.Run.compileSources(Run.scala:49)
        at dotty.tools.dotc.Run.compile(Run.scala:33)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:21)
        at dotty.tools.dotc.Driver.process(Driver.scala:44)
        at dotty.tools.dotc.Driver.process(Driver.scala:50)
        at dotty.tools.dotc.Driver.main(Driver.scala:54)
        at dotty.tools.dotc.Main.main(Main.scala)
cannot take signature of => Nothing{hk$0 = Int}#$apply
exception while transforming val x: Nothing{hk$0 = Int}#$apply = Test.foo[Nothing] of class class dotty.tools.dotc.ast.Trees$ValDef # 135
exception while transforming () extends Object() { this: Test.type => 
  def foo[M <: [hk$0] => ]: M[Int]#$apply = ???
  val x: Nothing{hk$0 = Int}#$apply = Test.foo[Nothing]
} of class class dotty.tools.dotc.ast.Trees$Template # 137
exception while transforming final module class Test$() extends Object() { this: Test.type => 
  def foo[M <: [hk$0] => ]: M[Int]#$apply = ???
  val x: Nothing{hk$0 = Int}#$apply = Test.foo[Nothing]
} of class class dotty.tools.dotc.ast.Trees$TypeDef # 138
exception while transforming package <empty> {
  final lazy module val Test: Test$ = new Test$()
  final module class Test$() extends Object() { this: Test.type => 
    def foo[M <: [hk$0] => ]: M[Int]#$apply = ???
    val x: Nothing{hk$0 = Int}#$apply = Test.foo[Nothing]
  }
} of class class dotty.tools.dotc.ast.Trees$PackageDef # 139
exception occurred while compiling tests/pos/hk_nothing.scala
Exception in thread "main" dotty.tools.dotc.core.Types$MissingType: cannot resolve reference to type Nothing{hk$0 = Int}.$apply
the classfile defining the type might be missing from the classpath
        at dotty.tools.dotc.core.TypeErasure.dotty$tools$dotc$core$TypeErasure$$sigName(TypeErasure.scala:447)
        at dotty.tools.dotc.core.TypeErasure$.sigName(TypeErasure.scala:134)
        at dotty.tools.dotc.core.Signature$.apply(Signature.scala:76)
        at dotty.tools.dotc.core.Types$MethodicType$class.resultSignature(Types.scala:2047)
        at dotty.tools.dotc.core.Types$ExprType.resultSignature(Types.scala:2238)
        at dotty.tools.dotc.core.Types$ExprType.computeSignature(Types.scala:2242)
        at dotty.tools.dotc.core.Types$MethodicType$class.signature(Types.scala:2057)
        at dotty.tools.dotc.core.Types$ExprType.signature(Types.scala:2238)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.signature(Denotations.scala:460)
        at dotty.tools.dotc.core.SymDenotations$SymDenotation.termRefWithSig(SymDenotations.scala:1060)
        at dotty.tools.dotc.typer.TypeAssigner$class.assignType(TypeAssigner.scala:398)
        at dotty.tools.dotc.typer.Typer.assignType(Typer.scala:57)
        at dotty.tools.dotc.ast.tpd$.polyDefDef(tpd.scala:208)
        at dotty.tools.dotc.ast.tpd$.DefDef(tpd.scala:184)
        at dotty.tools.dotc.ast.tpd$.DefDef(tpd.scala:181)
        at dotty.tools.dotc.transform.Getters.transformValDef(Getters.scala:70)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer.goValDef(TreeTransform.scala:823)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer.transformNamed(TreeTransform.scala:994)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer$$anonfun$transform$2.apply(TreeTransform.scala:1212)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer$$anonfun$transform$2.apply(TreeTransform.scala:1205)
        at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:154)
        at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:53)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer.transform(TreeTransform.scala:1204)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer.dotty$tools$dotc$transform$TreeTransforms$TreeTransformer$$transformStat$1(TreeTransform.scala:1238)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer$$anonfun$38.apply(TreeTransform.scala:1242)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer$$anonfun$38.apply(TreeTransform.scala:1242)
        at dotty.tools.dotc.core.Decorators$ListDecorator$.loop$1(Decorators.scala:51)
        at dotty.tools.dotc.core.Decorators$ListDecorator$.mapconserve$extension(Decorators.scala:67)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer.transformStats(TreeTransform.scala:1242)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer.transformUnnamed(TreeTransform.scala:1183)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer$$anonfun$transform$2.apply(TreeTransform.scala:1213)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer$$anonfun$transform$2.apply(TreeTransform.scala:1205)
        at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:154)
        at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:53)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer.transform(TreeTransform.scala:1204)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer.transformNamed(TreeTransform.scala:1011)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer$$anonfun$transform$2.apply(TreeTransform.scala:1212)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer$$anonfun$transform$2.apply(TreeTransform.scala:1205)
        at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:154)
        at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:53)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer.transform(TreeTransform.scala:1204)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer.dotty$tools$dotc$transform$TreeTransforms$TreeTransformer$$transformStat$1(TreeTransform.scala:1238)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer$$anonfun$38.apply(TreeTransform.scala:1242)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer$$anonfun$38.apply(TreeTransform.scala:1242)
        at dotty.tools.dotc.core.Decorators$ListDecorator$.loop$1(Decorators.scala:51)
        at dotty.tools.dotc.core.Decorators$ListDecorator$.mapconserve$extension(Decorators.scala:67)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer.transformStats(TreeTransform.scala:1242)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer.transformUnnamed(TreeTransform.scala:1192)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer$$anonfun$transform$2.apply(TreeTransform.scala:1213)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer$$anonfun$transform$2.apply(TreeTransform.scala:1205)
        at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:154)
        at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:53)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer.transform(TreeTransform.scala:1204)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer.macroTransform(TreeTransform.scala:563)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer.run(TreeTransform.scala:480)
        at dotty.tools.dotc.core.Phases$Phase$$anonfun$runOn$1.apply(Phases.scala:271)
        at dotty.tools.dotc.core.Phases$Phase$$anonfun$runOn$1.apply(Phases.scala:269)
        at scala.collection.immutable.List.map(List.scala:273)
        at dotty.tools.dotc.core.Phases$Phase$class.runOn(Phases.scala:269)
        at dotty.tools.dotc.transform.TreeTransforms$TreeTransformer.runOn(TreeTransform.scala:474)
        at dotty.tools.dotc.Run$$anonfun$compileUnits$1$$anonfun$apply$mcV$sp$1.apply(Run.scala:60)
        at dotty.tools.dotc.Run$$anonfun$compileUnits$1$$anonfun$apply$mcV$sp$1.apply(Run.scala:57)
        at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
        at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:186)
        at dotty.tools.dotc.Run$$anonfun$compileUnits$1.apply$mcV$sp(Run.scala:57)
        at dotty.tools.dotc.Run$$anonfun$compileUnits$1.apply(Run.scala:52)
        at dotty.tools.dotc.Run$$anonfun$compileUnits$1.apply(Run.scala:52)
        at dotty.tools.dotc.util.Stats$.monitorHeartBeat(Stats.scala:69)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:52)
        at dotty.tools.dotc.Run.compileSources(Run.scala:49)
        at dotty.tools.dotc.Run.compile(Run.scala:33)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:21)
        at dotty.tools.dotc.Driver.process(Driver.scala:44)
        at dotty.tools.dotc.Driver.process(Driver.scala:50)
        at dotty.tools.dotc.Driver.main(Driver.scala:54)
        at dotty.tools.dotc.Main.main(Main.scala)

Otherwise, when a higher-kinded type variable is instantiated to Nothing,
we will try to eta-expand it and trigger an assertion in
Definitions#LambdaTrait.
@odersky
Copy link
Contributor

odersky commented Dec 6, 2015

This fails again for the new hk scheme, even after trying an analogous fix. I think it reveals a deeper problem: Nothing is not a legal instance for a higher-kinded type. We need a principled way to avoid this. @smarter Could you investigate this under new scheme please?

@smarter
Copy link
Member Author

smarter commented Dec 6, 2015

I'll take a look.

odersky added a commit to dotty-staging/dotty that referenced this pull request Dec 11, 2015
@odersky
Copy link
Contributor

odersky commented Dec 11, 2015

Superseded by last commits in #994.

@odersky odersky closed this Dec 11, 2015
odersky added a commit to dotty-staging/dotty that referenced this pull request Dec 11, 2015
DarkDimius pushed a commit to dotty-linker/dotty that referenced this pull request May 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants