Skip to content

For an object X, X$ should be =:= to X.type #1447

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
smarter opened this issue Aug 10, 2016 · 3 comments
Closed

For an object X, X$ should be =:= to X.type #1447

smarter opened this issue Aug 10, 2016 · 3 comments
Assignees

Comments

@smarter
Copy link
Member

smarter commented Aug 10, 2016

This works in scalac but not in dotty:

case object X

object Test {
  val Alias = X

  val x: X.type = Alias
}
error: type mismatch:
 found   : X(Test.Alias)
 required: X.type
  val x: X.type = Alias
                  ^

Logging shows the issue:

[log frontend] ==> isSubType X$(Test.Alias) <:< X.type class dotty.tools.dotc.core.Types$TermRefWithSignature, class dotty.tools.dotc.core.Types$TermRefWithSignature?
[log frontend]   ==> isSubType X$ <:< X.type class dotty.tools.dotc.core.Types$CachedTypeRef, class dotty.tools.dotc.core.Types$TermRefWithSignature?
[log frontend]   <== isSubType X$ <:< X.type class dotty.tools.dotc.core.Types$CachedTypeRef, class dotty.tools.dotc.core.Types$TermRefWithSignature = false
[log frontend] <== isSubType X$(Test.Alias) <:< X.type class dotty.tools.dotc.core.Types$TermRefWithSignature, class dotty.tools.dotc.core.Types$TermRefWithSignature = false
smarter added a commit to dotty-staging/dotty that referenced this issue Aug 10, 2016
This allows objects to be easily aliased
@smarter smarter self-assigned this Aug 10, 2016
smarter added a commit to dotty-staging/dotty that referenced this issue Aug 10, 2016
This allows objects to be easily aliased
smarter added a commit that referenced this issue Aug 12, 2016
Fix #1447: Make X$ <:< X.type when X is an object
@sjrd
Copy link
Member

sjrd commented Aug 18, 2016

Hum ... I don't think this is the proper fix. X$ accepts null, whereas X.type does not. These types should not be equal.

The proper fix, IMO, is for Alias to be inferred to have type X.type, instead of X$.

@retronym
Copy link
Member

Not sure if this is the relevant or not, but I fixed a problem in scalac related to transitity of <:< and =:= being broken for:

    val tp1 = TypeRef(ThisType(EmptyPackageClass), moduleClass, Nil)
    val tp2 = SingleType(ThisType(EmptyPackageClass), module)
    val tp3 = ThisType(moduleClass)

Here's the test:

https://github.com/scala/scala/blob/b8e4d1f692c5712990b45f50625627015112df32/test/junit/scala/reflect/internal/TypesTest.scala#L38

@smarter
Copy link
Member Author

smarter commented Aug 18, 2016

@sjrd What you're suggesting might be better in principle but note that module classes are not nullable in dotty, so the difference might not be observable: https://github.com/lampepfl/dotty/blob/5a5f9d7ed37ca6449ef61ee5e0f6fbf9731df795/src/dotty/tools/dotc/core/SymDenotations.scala#L616-L618

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