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

unifier error messages appear in the wrong place #338

Open
MangoIV opened this issue Oct 25, 2024 · 9 comments
Open

unifier error messages appear in the wrong place #338

MangoIV opened this issue Oct 25, 2024 · 9 comments
Labels
bug Something isn't working error-message

Comments

@MangoIV
Copy link
Collaborator

MangoIV commented Oct 25, 2024

Hi! The error messages after unifying seem to appear in the wrong place. Simple example:

data A {a}
data B {b}
data C (a : A) {}

let f : C (b) {b}

In this example I expect C to be authoritative and the error to be reported on the type of f, however, the error is on the parameter on C.

this also happens with other errors like T-016 "Cannot automatically decided whether lhs and rhs unify"

@timsueberkrueb timsueberkrueb added the bug Something isn't working label Oct 25, 2024
@timsueberkrueb
Copy link
Collaborator

timsueberkrueb commented Oct 25, 2024

Hey, thanks for reporting this issue. We do indeed need to improve our error messages; I think there are more examples.

To fix this, the spans supplied to the type errors need to be adjusted. The errors are defined in https://github.com/polarity-lang/polarity/blob/main/lang/elaborator/src/result.rs. From there, one can find all references of individual errors in the codebase.

@MangoIV
Copy link
Collaborator Author

MangoIV commented Oct 25, 2024

From there, one can find all references of individual errors in the codebase.

it appears that there's just the span field is missing, e.g. when checking
B =? A, the TypCtor for B looks as follows:

TypCtor(TypCtor { span: None, name: Ident { span: Some(Span { start: ByteIndex(16), end: ByteIndex(17) }), id: "B" }, args: Args { args: [] } })

It looks like the span is there but only in name, not in span...

Is this expected? I think this is why it is missing in the error.

@MangoIV
Copy link
Collaborator Author

MangoIV commented Oct 26, 2024

I have traced back this empty span for TypCtor to very early in the pipeline. I wonder what the idea behind spans being allowed to be empty is; can one have a check on e.g. contained identifiers on spans and return Some span of the nested structure?

@BinderDavid
Copy link
Collaborator

BinderDavid commented Oct 26, 2024

I have traced back this empty span for TypCtor to very early in the pipeline. I wonder what the idea behind spans being allowed to be empty is; can one have a check on e.g. contained identifiers on spans and return Some span of the nested structure?

The reason for optional spans are the de/refunctionalization code actions. If a file gets parsed, lowered, typechecked, then all the spans should be Some(span), but when we modify the AST for code actions we set the spans to None.

(I am currently winding down from a week of OOPSLA, but I will have some time in the next few days to take a closer look :) )

Edit: Another reason is elaborated type information: When we annotate some subterm with an inferred type, then that type is represented by an AST, but it does not correspond to some text written by the user.

@timsueberkrueb
Copy link
Collaborator

The reason for optional spans are the de/refunctionalization code actions

This, but also syntactic sugar and substitution during elaboration (dependent pattern matching).

@timsueberkrueb
Copy link
Collaborator

data A {a}
data B {b}
data C (a : A) {}

let f : C (b) {b}

Okay, so what I think happens in this particular example is the following: In the declaration data B { b }, the constructor b is declared without type. This is allowed because B has no type parameters.

In lowering, we hence infer the type to TypCtor(TypCtor { span: None, name: Ident { span: Some(Span { start: ByteIndex(16), end: ByteIndex(17) }), id: "B" }, args: Args { args: [] } }):

This does not have a span simply because it does not occur in the program.

The spans in the ast are correct, but these are probably not the spans we want to use for this error message.

@timsueberkrueb
Copy link
Collaborator

For instance, if you change the program to:

data A {a}
data B {b: B} -- annotate the type of b explicitly
data C (a : A) {}

let f : C (b) {b}

The error message changes to:

Error: T-002

  × The following terms are not equal:
  │   1: B
  │   2: A
  │ 
   ╭─[file:///home/tim/Dev/polarity-lang/polarity/examples/foo.pol:1:1]
 1 │ data A {a}
 2 │ data B {b: B}
   ·            ┬
   ·            ╰── Source of (1)
 3 │ data C (a : A) {}
   ·             ┬
   ·             ╰── Source of (2)
 4 │ 
   ╰────

Which is better but it is still missing the information where the error originated from in f.

@MangoIV
Copy link
Collaborator Author

MangoIV commented Oct 27, 2024

Yeah… it would be good to annotate why it is trying to unify A and B and then put that in the error.

@MangoIV
Copy link
Collaborator Author

MangoIV commented Oct 27, 2024

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working error-message
Projects
None yet
Development

No branches or pull requests

3 participants