Skip to content

Add special handling for comparisons with Singleton types - #20474

Merged
smarter merged 1 commit into
scala:mainfrom
dotty-staging:fix-15030
May 28, 2024
Merged

Add special handling for comparisons with Singleton types#20474
smarter merged 1 commit into
scala:mainfrom
dotty-staging:fix-15030

Conversation

@odersky

@odersky odersky commented May 26, 2024

Copy link
Copy Markdown
Contributor

Fixes #15030

@odersky
odersky marked this pull request as ready for review May 27, 2024 11:43
@odersky
odersky requested a review from smarter May 27, 2024 11:43
@odersky odersky assigned odersky and smarter and unassigned odersky May 27, 2024

@smarter smarter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but this might need equivalent handling in tasty-query /cc @sjrd

@smarter
smarter merged commit 9b5ab2e into scala:main May 28, 2024
@smarter
smarter deleted the fix-15030 branch May 28, 2024 13:40
@noti0na1

noti0na1 commented May 28, 2024

Copy link
Copy Markdown
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 // error

In 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 failed

cc @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
@Kordyjan Kordyjan added this to the 3.5.1 milestone Jul 3, 2024
WojciechMazur pushed a commit that referenced this pull request Jul 8, 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

[Cherry-picked d04005c]
WojciechMazur added a commit that referenced this pull request Jul 9, 2024
…to LTS (#21126)

Backports #20474 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
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.

ThisType prefix leaks outside of the class it's defined instead of being substituted when referencing a member from the self-type (bug in asSeenFrom?)

4 participants