Skip to content
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

Add explanation to error when using nested quotes. #17338

Closed
steinybot opened this issue Apr 25, 2023 · 3 comments · Fixed by #18755
Closed

Add explanation to error when using nested quotes. #17338

steinybot opened this issue Apr 25, 2023 · 3 comments · Fixed by #18755
Assignees
Labels
area:documentation area:metaprogramming:quotes Issues related to quotes and splices area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement

Comments

@steinybot
Copy link

steinybot commented Apr 25, 2023

Compiler version

3.3.0-RC4

Minimized code

import scala.quoted.*

def test(using quotes: Quotes): Expr[Expr[Int]] =
  '{ '{ 1 } }

Reproduction: https://github.com/steinybot/bug-reports/tree/dotty/wrong-staging-level-multi-stage

Output

[error] 4 |  '{ '{ 1 } }
[error]   |     ^
[error]   |     access to parameter quotes from wrong staging level:
[error]   |      - the definition is at level 0,
[error]   |      - but the access is at level 1.

Expectation

According to the docs:

If the number of quotes exceeds the number of splices by more than one (effectively handling at run-time values of type Expr[Expr[T]], Expr[Expr[Expr[T]]], ...) then we talk about Multi-Stage Programming.

I thought that this example should have compiled and produces an Expr[Expr[Int]] which I could then evaluate twice with run.

Perhaps I have misunderstood, but if that is the case then I think the docs are misleading.

@steinybot steinybot added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 25, 2023
@Kordyjan Kordyjan added area:metaprogramming:quotes Issues related to quotes and splices and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 25, 2023
@Kordyjan
Copy link
Contributor

@nicolasstucki Could you clarify if this is indeed a bug?

@nicolasstucki nicolasstucki self-assigned this Apr 25, 2023
@nicolasstucki
Copy link
Contributor

This is not a bug. The error message is correct, but we might be able to give some extra information about the problem.

Here the issue is that each quote summons an implicit instance of type Quotes. In this example both use quotes. The issue is that quotes will not necessarily exist in the next stage. To solve this, the quote in the next stage should receive a Quotes that is defined in the next stage. A simple way to achieve this is to type the quote as Expr[Quotes ?=> Expr[Int]].

- def test(using quotes: Quotes): Expr[Expr[Int]] =
+ def test(using Quotes): Expr[Quotes ?=> Expr[Int]] =

@Kordyjan Kordyjan added area:reporting Error reporting including formatting, implicit suggestions, etc area:documentation labels Apr 25, 2023
@Kordyjan Kordyjan changed the title Unable to create Expr[Expr[...]] Add explanation to error when using nested quotes. Apr 25, 2023
@Kordyjan Kordyjan added this to the Future versions milestone Apr 25, 2023
@Kordyjan
Copy link
Contributor

The task should then be about adding an explanation to errors arising from nested quotes. The current error is misleading.

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Oct 24, 2023
@nicolasstucki nicolasstucki self-assigned this Oct 24, 2023
@bishabosha bishabosha added the better-errors Issues concerned with improving confusing/unhelpful diagnostic messages label Oct 25, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Oct 26, 2023
WojciechMazur pushed a commit that referenced this issue Jun 22, 2024
WojciechMazur pushed a commit that referenced this issue Jun 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:documentation area:metaprogramming:quotes Issues related to quotes and splices area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants