V2005 infinite_type
Inference would need a type that contains itself (the occurs check failed).
An error from the type phase. sakura explain V2005 prints this explanation offline.
Inference would need a type that contains itself (the occurs check failed). Usually a function was applied to itself or a value was put inside its own list; add an annotation to find where.
Wrong:
let _ = fn(x) { x(x) }Fixed:
let _ = fn(x: Int) { x }Wrong program
compiler/tests/ui/V2005_infinite_type.sakura, which the compiler's ui suite runs through sakura check:
fn omega() -> Unit { let _ = fn(x) { x(x) } }sakura check --json reports this record (pretty-printed; $DIR is the fixture's directory):
{
"schema_version": "1.0",
"kind": "diagnostic",
"id": "d:4d6248d8fec80f0c",
"code": "V2005",
"severity": "error",
"phase": "type",
"message": "this expression would need an infinite type: `?A` = `fn(?A) -> ?B ! ?e1`",
"snapshot": "sha256:$SNAPSHOT",
"symbol_id": "main::V2005_infinite_type::omega",
"spans": [
{
"uri": "file://$DIR/V2005_infinite_type.sakura",
"content_hash": "sha256:27f65a7229749e5131e2a3337167b8619997bac0ab6f4964d97034c905723ed7",
"start_byte": 71,
"end_byte": 75,
"role": "primary",
"label": "this has type `fn(?A) -> ?B ! ?e1`"
}
],
"related_ids": [],
"expected": {
"render": "?A"
},
"actual": {
"render": "fn(?A) -> ?B ! ?e1"
},
"obligation": null,
"counterexample": null,
"explanation_uri": "sakura://explain/V2005",
"fixes": []
}Fixed program
compiler/tests/ui/V2005_infinite_type.fixed.sakura, which sakura check accepts with no diagnostics:
fn omega() -> Unit { let _ = fn(x: Int) { x } }