Skip to content

Scala 3.3.0-RC2: inline value not considered to be immutable path #16804

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

Closed
soronpo opened this issue Feb 2, 2023 · 1 comment
Closed

Scala 3.3.0-RC2: inline value not considered to be immutable path #16804

soronpo opened this issue Feb 2, 2023 · 1 comment

Comments

@soronpo
Copy link
Contributor

soronpo commented Feb 2, 2023

The following compiles in Scala 3.2.2

Compiler version

v3.3.0-RC2

Minimized code

trait Bar[T]
given [T]: Bar[T] with {}
inline def foo[V](inline value: V)(using Bar[value.type]) : Unit = {} //error

Output

(value : V) is not a valid singleton type, since it is not an immutable path
inline def foo[V](inline value: V)(using Bar[value.type]) : Unit = {}

Expectation

No error.

@soronpo soronpo added itype:bug area:inline regression This worked in a previous version but doesn't anymore labels Feb 2, 2023
@soronpo soronpo changed the title Scala 3.3.0-RC2 regression inline value not cosidered to be immutable path Scala 3.3.0-RC2 regression: inline value not cosidered to be immutable path Feb 2, 2023
@SethTisue SethTisue changed the title Scala 3.3.0-RC2 regression: inline value not cosidered to be immutable path Scala 3.3.0-RC2 regression: inline value not considered to be immutable path Feb 2, 2023
@nicolasstucki
Copy link
Contributor

That error is expected. This bug was fixed in #15511.

Inline parameters are not immutable paths because they may refer to any number of distinct paths (0,1, 2,..). Consider this example.

inline def f(inline x: X)(using F[x.type]): Unit = ()
inline def g(inline x: X)(using F[x.type]): Unit = { x; () }
inline def h(inline x: X)(using F[x.type]): Unit = { x; x; () }

f(new X) // inlined as `()`. The value of the path is not created, and therefore it would be unsound to select it.

g(new X) // inlined as `{ new X; () }`. The value of the path is created after the path is selected. Not sure if that would be sound.

h(new X) // inlined as `{ new X; new X; () }`. Two values are created, and therefore two paths represent the same inline argument. It would be unsound to choose one of them.

@nicolasstucki nicolasstucki removed itype:bug regression This worked in a previous version but doesn't anymore labels Feb 2, 2023
@nicolasstucki nicolasstucki changed the title Scala 3.3.0-RC2 regression: inline value not considered to be immutable path Scala 3.3.0-RC2: inline value not considered to be immutable path Feb 2, 2023
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