brownplt / pyret-lang

The Pyret language.
Other
1.07k stars 110 forks source link

type error reporting in odd way #1730

Open shriram opened 6 months ago

shriram commented 6 months ago

Here's a full program:

fun sq(n :: Number): n * n end

modulo-power :: Number, Number, Number -> Number
fun modulo-power(base, exp, n):
  if exp == 0:
    1
  else:
    if num-round-even(exp):
      num-modulo(sq(modulo-power(base, (exp / 2), n)), n)
    else:
      num-modulo(base * modulo-power(base, (exp - 1), n), n)
    end
  end
end

The problem is num-round-even returns a number, and hence can't be used in a test position.

The type error does indeed say

image

However, note what it highlights:

image

The Boolean is actually the conditional position. Also, the then-clause has nothing to do with this.