Skip to content
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

Type disambiguation error in safe init checker caused by -Yexplicit-nulls #14682

Closed
Xavientois opened this issue Mar 13, 2022 · 0 comments · Fixed by #14755
Closed

Type disambiguation error in safe init checker caused by -Yexplicit-nulls #14682

Xavientois opened this issue Mar 13, 2022 · 0 comments · Fixed by #14755

Comments

@Xavientois
Copy link
Contributor

Ever since explicit nulls have been enabled, the error occurs when compiling the following code with both -Ysafe-init and -Yexplicit-nulls.

Compiler version

3.1.2-RC1

Minimized code

class Outer:
  sealed abstract class Name(val encoded: String) {
    type ThisName <: Name
    def compareTo(that: ThisName): Int = ???
  }

  class LocalName (encoded: String)
    extends Name(encoded) with Comparable[LocalName] {
    type ThisName = LocalName
  }

  val localName = LocalName("hello")
  println(localName)
  var count = 0

Output

Exception in thread "main" dotty.tools.dotc.core.TypeError: Failure to disambiguate overloaded reference with
  method compareTo in trait Comparable: (x$0: Outer.this.LocalName | Null): Int  and
  method compareTo in class Name: (that: Outer.this.LocalName#ThisName): Int
Failure to disambiguate overloaded reference with
  method compareTo in trait Comparable: (x$0: Outer.this.LocalName | Null): Int  and
  method compareTo in class Name: (that: Outer.this.LocalName#ThisName): Int while compiling example/Outer.scala
	at dotty.tools.dotc.core.Denotations$MultiDenotation.suchThat(Denotations.scala:1243)
	at dotty.tools.dotc.core.Denotations$Denotation.matchingDenotation(Denotations.scala:358)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.matchingMember(SymDenotations.scala:1300)
	at dotty.tools.dotc.transform.init.Semantic$.resolve(Semantic.scala:1578)
	at dotty.tools.dotc.transform.init.Semantic$.call(Semantic.scala:627)
	at dotty.tools.dotc.transform.init.Semantic$.tryPromote$$anonfun$1$$anonfun$1(Semantic.scala:949)
	at dotty.tools.dotc.core.Scopes$Scope.filter(Scopes.scala:102)
	at dotty.tools.dotc.core.Scopes$Scope.exists(Scopes.scala:109)
	at dotty.tools.dotc.transform.init.Semantic$.tryPromote$$anonfun$1(Semantic.scala:956)
	at scala.collection.immutable.List.exists(List.scala:395)
	at dotty.tools.dotc.transform.init.Semantic$.tryPromote(Semantic.scala:956)
	at dotty.tools.dotc.transform.init.Semantic$.promote(Semantic.scala:895)
	at dotty.tools.dotc.transform.init.Semantic$ArgInfo.promote(Semantic.scala:1051)
	at dotty.tools.dotc.transform.init.Semantic$.checkArgs$1$$anonfun$1(Semantic.scala:591)
	at scala.collection.immutable.List.flatMap(List.scala:293)
	at dotty.tools.dotc.transform.init.Semantic$.checkArgs$1(Semantic.scala:591)
	at dotty.tools.dotc.transform.init.Semantic$.call(Semantic.scala:613)
	at dotty.tools.dotc.transform.init.Semantic$Result.call(Semantic.scala:414)
	at dotty.tools.dotc.transform.init.Semantic$.cases(Semantic.scala:1151)
	at dotty.tools.dotc.transform.init.Semantic$.eval$$anonfun$1(Semantic.scala:1071)
	at dotty.tools.dotc.transform.init.Semantic$Cache$Cache.assume(Semantic.scala:314)
	at dotty.tools.dotc.transform.init.Semantic$.eval(Semantic.scala:1071)
	at dotty.tools.dotc.transform.init.Semantic$.init$$anonfun$4(Semantic.scala:1487)
	at scala.collection.immutable.List.foreach(List.scala:333)
	at dotty.tools.dotc.transform.init.Semantic$.init(Semantic.scala:1488)
	at dotty.tools.dotc.transform.init.Semantic$.cases(Semantic.scala:1265)
	at dotty.tools.dotc.transform.init.Semantic$.eval$$anonfun$1(Semantic.scala:1071)
	at dotty.tools.dotc.transform.init.Semantic$Cache$Cache.assume(Semantic.scala:314)
	at dotty.tools.dotc.transform.init.Semantic$.eval(Semantic.scala:1071)
	at dotty.tools.dotc.transform.init.Semantic$.dotty$tools$dotc$transform$init$Semantic$WorkList$$_$iterate$1(Semantic.scala:1008)
	at dotty.tools.dotc.transform.init.Semantic$WorkList.doTask(Semantic.scala:1019)
	at dotty.tools.dotc.transform.init.Semantic$WorkList.work$$anonfun$1(Semantic.scala:989)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:333)
	at dotty.tools.dotc.transform.init.Semantic$WorkList.work(Semantic.scala:989)
	at dotty.tools.dotc.transform.init.Semantic$.check(Semantic.scala:1033)
	at dotty.tools.dotc.transform.init.Checker.runOn$$anonfun$1(Checker.scala:38)
	at dotty.tools.dotc.transform.init.Semantic$.withInitialState(Semantic.scala:1044)
	at dotty.tools.dotc.transform.init.Checker.runOn(Checker.scala:40)
	at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:225)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1328)
	at dotty.tools.dotc.Run.runPhases$1(Run.scala:236)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:244)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:68)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:253)
	at dotty.tools.dotc.Run.compileSources(Run.scala:186)
	at dotty.tools.dotc.Run.compile(Run.scala:170)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:35)
	at dotty.tools.dotc.Driver.process(Driver.scala:195)
	at dotty.tools.dotc.Driver.process(Driver.scala:163)
	at dotty.tools.dotc.Driver.process(Driver.scala:175)
	at dotty.tools.dotc.Driver.main(Driver.scala:205)
	at dotty.tools.dotc.Main.main(Main.scala)

Expectation

This code should not cause the compiler to throw an exception.

The Comparable trait is defined as the Comparable<T> interface in Java, with its only method being public int compareTo(T o);, so the code above would be expected to be a correct implementation of the trait (assuming we were to provide an actual implementation).

@olhotak @liufengyun

@Xavientois Xavientois added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 13, 2022
@noti0na1 noti0na1 self-assigned this Mar 14, 2022
@prolativ prolativ added itype:crash area:nullability itype:bug and removed itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 14, 2022
@noti0na1 noti0na1 linked a pull request Mar 23, 2022 that will close this issue
@Kordyjan Kordyjan added this to the 3.1.3 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants