Skip to content

default arguments of inline functions are not constant (leading to error message leaking implementation details) #15286

Open
@rmgk

Description

@rmgk

Compiler version

3.1.2

Minimized example

inline def fun(a: String = "default"): Int =
  inline if a == "default" then 2 else 3

@main def run(): Unit = println(fun())

Output

Macro.scala:6:33: Cannot reduce `inline if` because its condition is not a constant value: a$proxy1.==("default") [6:33]

Expectation

At the very least, the error is confusing because it leaks the implementation details of default arguments.

The whole thing works as expected if a is marked as inline, thus maybe having the proxy “constant” should be the default for inline methods?

(As motivation, this pattern is somewhat useful to use a different implementation when default arguments are not changed)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions