Skip to content

inline if error suggests it expects a literal expression #10107

Closed
@deusaquilus

Description

@deusaquilus

Minimized code

Say we make a simple macro that just returns the value true.

object Proc {
  inline def isTrue: Boolean = ${ isTrueImpl }
  def isTrueImpl(using qctx: QuoteContext) = {
    Expr(true) // even tried: Literal(Constant(true).seal.asExprOf[Boolean])
  }
}

Now if we use that with an inline if statement:

  inline def oneOf(): String = {
    inline if (isTrue)
      "foo"
    else
      "bar"
  }

Then when I run that:

oneOf()

The following error happens...

Output

[error]    |    cannot reduce inline if
[error]    |     its condition   miniquill.ListProc.isTrue
[error]    |     is not a constant value

Expectation

I think this should be more intelligent about looking at the AST and detecting if there is a constant value. I even tried making oneOf return Literal(Constant(true)) but it still did not work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions