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

Improve error message for bad args to operators #1704

Open
jpolitz opened this issue Sep 13, 2023 · 3 comments
Open

Improve error message for bad args to operators #1704

jpolitz opened this issue Sep 13, 2023 · 3 comments

Comments

@jpolitz
Copy link
Member

jpolitz commented Sep 13, 2023

fun insert<T>(e :: T, l :: List<T>)
  -> List<T>:
  cases (List) l:
    | empty => [list: e]
    | link(f, r) =>
      if e < f:
        link(e, l)
      else:
        link(f, insert(e, r))
      end
  end
end

fun isort<T>(l :: List<T>)
  -> List<T>:
  cases (List) l:
    | empty => empty
    | link(f, r) =>
      insert(f, isort(r))
  end
end

With TC on yields: The type checker rejected your program because it found a T but it expected a an object type.

I think we could do better here, and make the type that's synthesized have a little more explanation than “an object type”.

@jpolitz
Copy link
Member Author

jpolitz commented Sep 13, 2023

A pretty specific type is synthed (

shadow context = context.add-variable(obj-exists).add-variable(other-type).add-variable(ret-type).add-field-constraint(obj-exists, method-name, t-arrow([list: other-type], ret-type, app-loc, false))
), so the issue must be that in constraint solving the related error just gets called “an object type” – harder to track down; that string constant appears in a few places.

@blerner
Copy link
Member

blerner commented Sep 14, 2023

Isn't it just failing on "T isn't an object", and never getting to the field-level constraints?

@jpolitz
Copy link
Member Author

jpolitz commented Sep 15, 2023

Right, I think that's what I was saying – in constraint solving, it fails on “is type variable T an object type” and gives an error with that constant string.

One idea is to, when we see “S is not object” (for any type S), we search the constraint set for field constraints and report those.

That or augment whatever obj-exists is with more information to report in constraints, even up to something that says, effectively “This one was created as a constraint for lessthan” and use that to augment the error on failure.

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