Skip to content

inline val for opaque type alias for literal type 'must have a literal constant type' #13851

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
armanbilge opened this issue Oct 30, 2021 · 1 comment · Fixed by #13857
Closed
Assignees
Milestone

Comments

@armanbilge
Copy link
Contributor

armanbilge commented Oct 30, 2021

Compiler version

3.1.1-RC1

Minimized code

// This compiles:
opaque type One = 1
inline val One: One = 1

// But this does not:
opaque type Max = Int.MaxValue.type
inline val Max: Max = Int.MaxValue
// inline value must have a literal constant type

// However, this does:
inline val MaxValue: Int.MaxValue.type = Int.MaxValue

Output

[error] 33 |inline val Max: Max = Int.MaxValue
[error]    |                ^^^
[error]    |                inline value must have a literal constant type
[error] one error found

Expectation

If it is possible to inline a value of literal type Int.MaxValue, it should be possible to inline an opaque alias of that.

@armanbilge armanbilge changed the title inline val for opaque type inline val for opaque type alias for literal value 'must have a literal constant type' Oct 30, 2021
@armanbilge armanbilge changed the title inline val for opaque type alias for literal value 'must have a literal constant type' inline val for opaque type alias for literal type 'must have a literal constant type' Oct 30, 2021
@nicolasstucki
Copy link
Contributor

Actually inline val One: One = 1 should have been rejected because One is not generally known to be a constant value. It is only known in the scope where the opaque type is defined.

For example in this test we will not be able to inline it and will fail with a more confusing error message.

object Num {
  opaque type One = 1
  inline val One: One = 1
}

def test = Num.One
//         ^^^^^^^
//         getter One is declared as `inline`, but was not inlined
//
//         Try increasing `-Xmax-inlines` above 32

@nicolasstucki nicolasstucki self-assigned this Nov 1, 2021
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Nov 1, 2021
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Nov 1, 2021
`inline val`s cannot contain opaque aliases as these cannot be inlined
through their type due to their opaqueness. We can support `inline def`
with opaque types.

Fixes scala#13851
Fixes scala#13852
olsdavis pushed a commit to olsdavis/dotty that referenced this issue Apr 4, 2022
`inline val`s cannot contain opaque aliases as these cannot be inlined
through their type due to their opaqueness. We can support `inline def`
with opaque types.

Fixes scala#13851
Fixes scala#13852
@Kordyjan Kordyjan added this to the 3.1.2 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants