Skip to content

Constant fold expressions of type Null and Unit #12198

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

Open
nicolasstucki opened this issue Apr 23, 2021 · 2 comments
Open

Constant fold expressions of type Null and Unit #12198

nicolasstucki opened this issue Apr 23, 2021 · 2 comments

Comments

@nicolasstucki
Copy link
Contributor

Compiler version

3.0.0-RC3

Expectation

Constant folding should be able to handle Null and Unit.

Possible use cases

class A[T]:
  val x: T
object B extends A[Unit]:
    val x: Unit = ()
object C extends A[Null]:
    val x: Null = ()
def test1 =  B.x // should be constant folded to `()`
def test2 = C.x // should be constant folded to `null`
inline val n = null
inline val u = ()
def test1 = n // should be constant folded to `null`
def test2 = u // should be constant folded to `()`
@sjrd
Copy link
Member

sjrd commented Apr 23, 2021

The first use case is probably invalid because it won't account for exceptions during initialization. Notably val x: Unit = ???.

@nicolasstucki
Copy link
Contributor Author

nicolasstucki commented Apr 23, 2021

In the first case, we could still transform C.x into { C; null } which might be used for further constant folding and avoid the call of the x getter.

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

2 participants