-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More principled filtering of abstract values in initialization check (#…
…20548) More principled filtering of abstract values in initialization check. It ports the similar improvement to the global initialization checker #19612.
- Loading branch information
Showing
3 changed files
with
60 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class A(o: O): | ||
var a = 20 | ||
|
||
class B(o: O): | ||
var b = 20 | ||
|
||
class O: | ||
val o: A | B = new A(this) | ||
if o.isInstanceOf[A] then | ||
o.asInstanceOf[A].a += 1 | ||
else | ||
o.asInstanceOf[B].b += 1 // o.asInstanceOf[B] is treated as bottom | ||
|
||
// prevent early promotion | ||
val x = 10 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class A(c: C): | ||
val f: Int = 10 | ||
def m() = f | ||
|
||
class B(c: C): | ||
val f: Int = g() // warn | ||
def g(): Int = f | ||
|
||
class C(x: Int): | ||
val a: A | B = if x > 0 then new A(this) else new B(this) | ||
|
||
def cast[T](a: Any): T = a.asInstanceOf[T] | ||
|
||
val c: A = a.asInstanceOf[A] // abstraction for c is {A, B} | ||
val d = c.f // treat as c.asInstanceOf[owner of f].f | ||
val e = c.m() // treat as c.asInstanceOf[owner of m].m() | ||
val c2: B = a.asInstanceOf[B] | ||
val g = c2.f // no error here | ||
|