Skip to content

Try to fix #926 by providing more information about type variable origins #932

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

Closed
wants to merge 1 commit into from

Conversation

jiribenes
Copy link
Contributor

@jiribenes jiribenes commented Apr 10, 2025

I quickly hacked together a prototype of a way to resolve #926.
Please, feel free to assign yourself and clean this up. :)

Example:

type Result[T, E] {
  Success(value: T)
  Failure(errors: List[E])
}

def addError[T, E](result: Result[T, E], e: E) =
  result match {
    case Success(value)  => Failure([e])
    case Failure(errors) => Failure(Cons(e, errors))
  }

def main() = ()

now reports:

[error] ambig.effekt:6:1: Cannot fully infer type for addError: [T, E](Result[T, E], E) => Result[T, E], because the following type variables are ambiguous: T from Call(IdTarget(IdRef(List(),Failure)),List(),List(Call(IdTarget(IdRef(List(),Cons)),List(),List(Var(IdRef(List(),e)), Call(IdTarget(IdRef(List(),Nil)),List(),List(),List())),List())),List())
def addError[T, E](result: Result[T, E], e: E) =
^
[error] ambig.effekt:8:29: Cannot infer type argument T of IdTarget(IdRef(List(),Failure)), maybe consider annotating it?
    case Success(value)  => Failure([e])
                            ^^^^^^^^^^^^
[error] ambig.effekt:9:29: Cannot infer type argument T of IdTarget(IdRef(List(),Failure)), maybe consider annotating it?
    case Failure(errors) => Failure(Cons(e, errors))
                            ^^^^^^^^^^^^^^^^^^^^^^^^

What I'd reasonably want it to report is:

[error] ambig.effekt:6:1: Cannot fully infer type for addError: [T, E](Result[T, E], E) => Result[T, E], because the following type variables are ambiguous: T from Failure[T, E]
def addError[T, E](result: Result[T, E], e: E) =
^
[error] ambig.effekt:8:29: Cannot infer type argument T of Failure[T, E], maybe consider annotating it?
    case Success(value)  => Failure([e])
                            ^^^^^^^^^^^^
[error] ambig.effekt:9:29: Cannot infer type argument T of Failure[T, E], maybe consider annotating it?
    case Failure(errors) => Failure(Cons(e, errors))
                            ^^^^^^^^^^^^^^^^^^^^^^^^

My ideal error message would be:

[error] ambig.effekt:6:1: Cannot fully infer type for addError: [T, E](Result[T, E], E) => Result[T, E], because of ambiguous type arguments.
def addError[T, E](result: Result[T, E], e: E) =
^
    [note] ambig.effekt:8:29: Cannot infer type argument T of Failure[T, E] used here, consider annotating it.
        case Success(value)  => Failure([e])
                                ^^^^^^^^^^^^
    [note] ambig.effekt:9:29: Cannot infer type argument T of Failure[T, E] used here, consider annotating it.
        case Failure(errors) => Failure(Cons(e, errors))
                                ^^^^^^^^^^^^^^^^^^^^^^^^

TODOs:

  • get symbol from the call tree to pretty-print origin of the type variable
  • clean up

@jiribenes jiribenes added help wanted Extra attention is needed errormessage labels Apr 10, 2025
@jiribenes
Copy link
Contributor Author

Nobody seems interested in finishing this and it's currently not a priority, so I'm closing the PR. Feel free to continue with this if you want to though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
errormessage help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typer failure on ambiguous type argument
1 participant