hydromatic / morel

Standard ML interpreter, with relational extensions, implemented in Java
Apache License 2.0
291 stars 15 forks source link

AssertionError in TypeResolver.deducePatType when distinct variables have the same name #197

Open julianhyde opened 11 months ago

julianhyde commented 11 months ago

The function

fun foo (f, n) =
  let
    fun factorial 0 = 1
      | factorial n = f (n * factorial (n - 1))
  in
    factorial n
  end;

throws the following exception:

Exception in thread "main" java.lang.AssertionError
    at net.hydromatic.morel.compile.TypeResolver.deducePatType(TypeResolver.java:1117)
    at net.hydromatic.morel.compile.TypeResolver.deduceMatchListType(TypeResolver.java:675)
    at net.hydromatic.morel.compile.TypeResolver.deduceType(TypeResolver.java:303)

The similar function

fun foo (f, n) =
  let
    fun factorial 0 = 1
      | factorial k = f (k * factorial (k - 1))
  in
    factorial n
  end;

has no error; the only difference is that the shadowing variable n is renamed to k. Perhaps the problem is caused by duplicate variable names.