Skip to content

A code example doesn't work #10521

Closed
@ShapelessCat

Description

@ShapelessCat

In the section "Transparent Inline Methods" of Scala 3 Macro Tutorial / Inline.md, there is a code example:

transparent inline def default(inline name: String): Any =
  inline if name == "Int" then 0
  else inline if name == "String" then ""
  else ...

I run default("Int") in console (Scala 3.0.0-M2), and I see this error message:

default("Int")
1 |default("Int")
  |^^^^^^^^^^^^^^
  |Cannot reduce `inline if` because its condition is not a constant value: "Int".==("Int")
  | This location contains code that was inlined from rs$line$1:2

I also tried to implement it with inline match, and it works:

transparent inline def default(inline name: String): Any =
  inline name match
    case "Int"      => 0
    case "String" => ""
    case _            => ...

It seems this difference between inline if and inline match is not reasonable, but I'm not sure.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions