Skip to content

Fix treatment of bottom types in OrType#join and baseType computations #11979

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

Merged
merged 3 commits into from
Apr 5, 2021

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Apr 3, 2021

Fixes #11968

@odersky odersky requested a review from noti0na1 April 3, 2021 16:56
@noti0na1
Copy link
Member

noti0na1 commented Apr 3, 2021

Could you extend test to this? Thanks

// Test selecting member of nullable classes

class A {
  def get(): Int = 0
}

class B extends A {}

class C extends A {}

def test1 = {
  val s: String | Null = ???
  val l = s.length

  val a: A | Null = new A
  a.get()

  val bc: B | C = new B
  bc.get()

  val bcn: B | (C | Null) = new C
  bcn.get()

  val bnc: (B | Null) | C = null
  bnc.get()

  val abcn: A | B | C | Null = new A
  abcn.get()
}

def test2 = {
  val s: String | Nothing = ???
  val l = s.length

  val a: A | Nothing = new A
  a.get()

  val bc: B | C = new B
  bc.get()

  val bcn: B | (C | Nothing) = new C
  bcn.get()

  val bnc: (B | Nothing) | C = new B
  bnc.get()

  val abcn: A | B | C | Nothing = new A
  abcn.get()
}

It seems subtyping check on both side is not enough.

-- [E008] Not Found Error: Stest.scala:22:6 ------------------------------------
22 |  bcn.get()
   |  ^^^^^^^
   |  value get is not a member of B | (C | Null)
-- [E008] Not Found Error: Stest.scala:25:6 ------------------------------------
25 |  bnc.get()
   |  ^^^^^^^
   |  value get is not a member of B | Null | C
-- [E008] Not Found Error: Stest.scala:42:6 ------------------------------------
42 |  bcn.get()
   |  ^^^^^^^
   |  value get is not a member of B | (C | Nothing)
-- [E008] Not Found Error: Stest.scala:45:6 ------------------------------------
45 |  bnc.get()
   |  ^^^^^^^
   |  value get is not a member of B | Nothing | C

Copy link
Member

@noti0na1 noti0na1 left a comment

Choose a reason for hiding this comment

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

LGTM

@odersky odersky merged commit 0d2bb9e into scala:master Apr 5, 2021
@odersky odersky deleted the fix-11968 branch April 5, 2021 09:03
@Kordyjan Kordyjan added this to the 3.0.1 milestone Aug 2, 2023
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.

Unable to select member of nullable user-defined class
3 participants