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

Unhelpful error message when nested attributes are used with wrong repetition depth #525

Closed
ellifteria opened this issue Jul 27, 2024 · 1 comment

Comments

@ellifteria
Copy link

When an incorrect repetition depth is used within a definition macro or an expression macro, Racket and DrRacket don't trace the error to the correct line.

In the following Rhombus code, x is used with the wrong repetition depth:

#lang rhombus/static/and_meta

def [[x, ...], ...] = [[1, 2], [3, 4]]

[x, ...]

And Racket throws an error that correctly traces the wrong repetition depth to the correct line:

example.rhm:5:1: x: used with wrong repetition depth
  in: x
  expected: 2
  actual: 1
  #(73 1)

However, if an incorrect repetition depth is used with a definition or expression macro (shown here as a definition macro but switching defn.macro to expr.macro gives the same error message), as in this code where a.var is used with the wrong depth:

#lang rhombus/static/and_meta

meta syntax_class SyntaxClass
| '$variable':
    field [var, ...] = [variable]

defn.macro 'random_macro [$(a :: SyntaxClass), ...]':
  def [[b, ...], ...] = [[a.var, ...]]
  '1'

The error message traces the wrong usage to a Racket file in the Rhombus source instead of the line in the macro where the wrong repetition depth is used:

Library/Racket/8.13/pkgs/rhombus-lib/rhombus/private/amalgam/pattern-variable.rkt:112:64: a: used with wrong repetition depth
  in: a.var
  expected: 2
  actual: 1

Ideally, the error message should trace the error back to line 8 in this file, instead of to a Racket file in the Rhombus source.

@usaoc
Copy link
Collaborator

usaoc commented Aug 9, 2024

This is a problem specifically with pattern variables, which handle repetitions in a unique way (related: #534). For example, the following program can reproduce the same unhelpful error message:

#lang rhombus

syntax_class SyntaxClass
| '$variable':
    field [var, ...] = [variable]

match '[a, b, c]'
| '[$(a :: SyntaxClass), ...]':
    [[a.var, ...]]

and the following program, too:

#lang rhombus

match '[a, b, c]'
| '[$(pattern a
      | '$variable':
          field [var, ...] = [variable]),
    ...]':
    [[a.var, ...]]

In fact, the source location points to the repetition handler in pattern variables.

@usaoc usaoc changed the title Unhelpful error message when wrong repetition depth used in macro Unhelpful error message when nested attributes are used with wrong repetition depth Aug 9, 2024
@usaoc usaoc closed this as completed in a16adbf Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants