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

Default argument in recursive functions crashes compiler #2151

Closed
marcusroberts opened this issue Aug 22, 2024 · 1 comment · Fixed by #2154
Closed

Default argument in recursive functions crashes compiler #2151

marcusroberts opened this issue Aug 22, 2024 · 1 comment · Fixed by #2154
Assignees

Comments

@marcusroberts
Copy link
Member

marcusroberts commented Aug 22, 2024

When I set a default value for an argument in recursive functions, the compiler crashes with

Failure("Impossible: optional argument with non-option type")


let rec parenthesizedExpression = () => {
  let expression1 = expression(0)
  expression1
}

and expression = (prec=0) => {  // setting the default value here causes the compiler crash
  0
}

provide let parse = (source: String) => {
  expression(0)
}

@spotandjake
Copy link
Member

spotandjake commented Aug 29, 2024

This is a really interesting error, it occurs when Apply_too_many_arguments is hit in typecore.re, interestingly if you pass the arguments as named parameters we get a different impossible error. This error also only seems to occur when the function being used is called before its defintion in an and statement.

In grain we require arguments to be passed with their label in the defaulted case normally we have a pretty error for this but it seems something is messing it up. I traced this issue back a little and we seem to be producing the wrong type here let funct = type_exp(env, func); line 1382 in type_expect we are producing a function with a (Default(_), TTyVar(None)) instead of an optional type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants