V2001 type_mismatch
An expression has a different type from the one its context requires.
An error from the type phase. sakura explain V2001 prints this explanation offline.
An expression has a different type from the one its context requires. expected and actual
carry both types.
Wrong:
fn double(x: Int) -> Int { x * 2.0 }Fixed:
fn double(x: Int) -> Int { x * 2 }Wrong program
compiler/tests/ui/V2001_type_mismatch.sakura, which the compiler's ui suite runs through sakura check:
fn age() -> Int { "forty" }sakura check --json reports this record (pretty-printed; $DIR is the fixture's directory):
{
"schema_version": "1.0",
"kind": "diagnostic",
"id": "d:c2099b6a910033c7",
"code": "V2001",
"severity": "error",
"phase": "type",
"message": "expected `Int`, found `String`",
"snapshot": "sha256:$SNAPSHOT",
"symbol_id": "main::V2001_type_mismatch::age",
"spans": [
{
"uri": "file://$DIR/V2001_type_mismatch.sakura",
"content_hash": "sha256:ba191e33c0daecd6ab8441edc074708a7abbc21c3a46cbcf5927c1a9a99784d0",
"start_byte": 52,
"end_byte": 59,
"role": "primary",
"label": "this has type `String`"
}
],
"related_ids": [],
"expected": {
"render": "Int"
},
"actual": {
"render": "String"
},
"obligation": null,
"counterexample": null,
"explanation_uri": "sakura://explain/V2001",
"fixes": []
}Fixed program
compiler/tests/ui/V2001_type_mismatch.fixed.sakura, which sakura check accepts with no diagnostics:
fn age() -> Int { 40 }