Skip to content

A code example doesn't work #10521

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

Closed
ShapelessCat opened this issue Nov 26, 2020 · 2 comments · Fixed by #11111
Closed

A code example doesn't work #10521

ShapelessCat opened this issue Nov 26, 2020 · 2 comments · Fixed by #11111
Assignees
Milestone

Comments

@ShapelessCat
Copy link
Contributor

ShapelessCat commented Nov 26, 2020

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.

@nicolasstucki nicolasstucki transferred this issue from lampepfl/scala3-macro-tutorial Nov 26, 2020
@ShapelessCat
Copy link
Contributor Author

I update the description.
Is this a bug?

@nicolasstucki
Copy link
Contributor

It is a bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants