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

Update elaboration error messages involving constants and infix pats/exps #554

Conversation

MatthewFluet
Copy link
Member

No description provided.

Carry the exact (literal) text used for constants (literals) from lexer through
to elaboration, so that error message using the constants appear as they are
written in the source file.

Consider the program (with type errors):

    val _ = "a甲\010" ^ (Substring.full "b乙\n")
    val _ : word = 0xabcd
    val _ : string = "abc\uaBcD\UAbCdEf00xyz"

Previously, the error messages were:

    Error: z.sml 1.9-1.46.
      Function applied to incorrect argument.
        expects: _ * [string]
        but got: _ * [char VectorSlice.slice]
        in: ^ ("a\231\148\178\n", Substring.full "b\228\185\153\n")
    Error: z.sml 2.5-2.21.
      Pattern and expression disagree.
        pattern:    [word]
        expression: [int]
        in: val _: word = 43981
    Error: z.sml 3.18-3.41.
      String constant with characters too large for type: #"\uABCD", #"\UABCDEF00".
        type: string

Now, the error messages are:

    Error: z.sml 1.9-1.46.
      Function applied to incorrect argument.
        expects: _ * [string]
        but got: _ * [char VectorSlice.slice]
        in: ^ ("a甲\010", Substring.full "b乙\n")
    Error: z.sml 2.5-2.21.
      Pattern and expression disagree.
        pattern:    [word]
        expression: [int]
        in: val _: word = 0xabcd
    Error: z.sml 3.18-3.41.
      String constant with characters too large for type: #"\uaBcD", #"\UAbCdEf00".
        type: string
        in: "abc\uaBcD\UAbCdEf00xyz"

Closes MLton#517
Record whether a pattern or expression application originated from an
infix application and layout such patterns and expressions as
appropriate, so that error messages appear as they are written in the
source file.

Consider the program (with type errors):

    datatype t = $ of int * int
    infix $
    val _ = case 1 $ 1  of true $ false => false
    val _ = 1 + 2.0 + "b" + true

Previously, the error messages were:

    Error: z.sml 3.24-3.35.
      Constructor applied to incorrect argument in pattern.
        expects: [int] * [int]
        but got: [bool] * [bool]
        in: $ (true, false)
    Error: z.sml 4.9-4.15.
      Function applied to incorrect argument.
        expects: _ * [int]
        but got: _ * [real]
        in: + (1, 2.0)
    Error: z.sml 4.9-4.21.
      Function applied to incorrect argument.
        expects: _ * [int]
        but got: _ * [string]
        in: + (+ (1, 2.0), "b")
    Error: z.sml 4.9-4.28.
      Function applied to incorrect argument.
        expects: _ * [int]
        but got: _ * [bool]
        in: + (+ (+ (1, 2.0), "b"), true)

Now, the error messages are:

    Error: z.sml 3.24-3.35.
      Constructor applied to incorrect argument in pattern.
        expects: [int] * [int]
        but got: [bool] * [bool]
        in: true $ false
    Error: z.sml 4.9-4.15.
      Function applied to incorrect argument.
        expects: _ * [int]
        but got: _ * [real]
        in: 1 + 2.0
    Error: z.sml 4.9-4.21.
      Function applied to incorrect argument.
        expects: _ * [int]
        but got: _ * [string]
        in: (1 + 2.0) + "b"
    Error: z.sml 4.9-4.28.
      Function applied to incorrect argument.
        expects: _ * [int]
        but got: _ * [bool]
        in: ((1 + 2.0) + "b") + true
@MatthewFluet MatthewFluet merged commit 3f76105 into MLton:master Mar 17, 2024
9 checks passed
@MatthewFluet MatthewFluet deleted the constant-and-infix-elaborate-error-messages branch March 17, 2024 21:55
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

Successfully merging this pull request may close these issues.

1 participant