Add special handling for comparisons with Singleton types#20474
Merged
smarter merged 1 commit intoscala:mainfrom May 28, 2024
Merged
Add special handling for comparisons with Singleton types#20474smarter merged 1 commit intoscala:mainfrom
smarter merged 1 commit intoscala:mainfrom
Conversation
Member
|
I don't think the rule in this PR is correct: class A
class B extends A
def f(a: A, c: A) =
val b1: a.type = a
val b2: a.type & B = a.asInstanceOf[a.type & B]
val b3: c.type & A = c
val b4: a.type | c.type = c
val d1: b1.type = a
val d2: b2.type = a // ok
val d3: b3.type = a // error
val d4: b4.type = a // errorIn 3.4.2: > scala-cli compile -S 3.4 Stest.scala
Compiling project (Scala 3.4.2, JVM (21))
[error] ./Stest.scala:324:21
[error] Found: (a : A)
[error] Required: (b3 : (c : A) & A)
[error] val d3: b3.type = a // error
[error] ^
[error] ./Stest.scala:325:21
[error] Found: (a : A)
[error] Required: (b4 : (a : A) | (c : A))
[error] val d4: b4.type = a // error
[error] ^
Error compiling project (Scala 3.4.2, JVM (21))
Compilation failedcc @sjrd |
odersky
added a commit
to dotty-staging/dotty
that referenced
this pull request
May 28, 2024
As usual, OrTypes need to be excluded. a.type | b.type is not effectively a singleton. It seems to be an easy trap to fall into. Follow-up to scala#20474
noti0na1
added a commit
that referenced
this pull request
May 28, 2024
As usual, OrTypes need to be excluded. a.type | b.type is not effectively a singleton. It seems to be an easy trap to fall into. Follow-up to #20474
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #15030