Skip to content

Default value of inline parameter is not inlined when the path involves a pattern match against null. #23177

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
readren opened this issue May 16, 2025 · 1 comment

Comments

@readren
Copy link

readren commented May 16, 2025

Compiler version

3.7.0 with no scala options

Minimized code

class Something

transparent inline def test(inline oNio: Something | Null = null, inline offset: Int = 0): Int = {
	inline val index = inline oNio match {
		case null => offset
		case nio: Something => -1
	}
	index
}

@main def check(): Unit = {
	test(Something(), 0) // compiles
	test(Something()) // compiles
	test(null, 0) // compiles
	test(null) // complains with: inline value must have a literal constant type 
}

Output

[error] 19 |            test(null) // complains with: inline value must have a literal constant type
[error]    |            ^^^^^^^^^^
[error]    |            inline value must have a literal constant type
[error]    |----------------------------------------------------------------------------
[error]    |Inline stack trace
[error]    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[error]    |This location contains code that was inlined from Borrame.scala:9
[error]  9 |                    case null => offset
[error]    |                                 ^^^^^^
[error]     ----------------------------------------------------------------------------

Expectation

The call to test(null) should compile.

@readren readren added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels May 16, 2025
@som-snytt
Copy link
Contributor

som-snytt commented May 16, 2025

null does not matter. (Switch the RHS of the cases. It fails on the branch exercising the default.)

Deleting index works, so that the RHS is just the match.

Changing index to def complains about nested inline def.

It doesn't help to define the default as zero where inline def zero: 0 = 0.

Defining the default as inline offset: 0 = 0 does work, so it must be widened somewhere. Maybe defaults are always def.

          {
            inline val index: (test$default$2 : => Int) =
              i23177$package.test$default$2
            index:Int
          }

@Gedochao Gedochao added area:inline and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels May 21, 2025
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

3 participants