Dotty: A code example doesn't work

Created on 26 Nov 2020  路  2Comments  路  Source: lampepfl/dotty

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.

inline bug

Most helpful comment

It is a bug

All 2 comments

I update the description.
Is this a bug?

It is a bug

Was this page helpful?
0 / 5 - 0 ratings

Related issues

liufengyun picture liufengyun  路  3Comments

dwijnand picture dwijnand  路  3Comments

ohze picture ohze  路  3Comments

milessabin picture milessabin  路  3Comments

m-sp picture m-sp  路  3Comments