mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +00:00
Constrain + solve crash
This commit is contained in:
parent
9dc489c2b0
commit
e2b30e5301
13 changed files with 194 additions and 60 deletions
|
@ -1086,7 +1086,36 @@ pub fn can_problem<'b>(
|
|||
} else {
|
||||
"TOO FEW TYPE ARGUMENTS".to_string()
|
||||
};
|
||||
|
||||
severity = Severity::RuntimeError;
|
||||
}
|
||||
Problem::UnappliedCrash { region } => {
|
||||
doc = alloc.stack([
|
||||
alloc.concat([
|
||||
alloc.reflow("This "), alloc.keyword("crash"), alloc.reflow(" doesn't have a message given to it:")
|
||||
]),
|
||||
alloc.region(lines.convert_region(region)),
|
||||
alloc.concat([
|
||||
alloc.keyword("crash"), alloc.reflow(" must be passed a message to crash with at the exact place it's used. "),
|
||||
alloc.keyword("crash"), alloc.reflow(" can't be used as a value that's passed around, like functions can be - it must be applied immediately!"),
|
||||
])
|
||||
]);
|
||||
title = "UNAPPLIED CRASH".to_string();
|
||||
severity = Severity::RuntimeError;
|
||||
}
|
||||
Problem::OverAppliedCrash { region } => {
|
||||
doc = alloc.stack([
|
||||
alloc.concat([
|
||||
alloc.reflow("This "),
|
||||
alloc.keyword("crash"),
|
||||
alloc.reflow(" has too many values given to it:"),
|
||||
]),
|
||||
alloc.region(lines.convert_region(region)),
|
||||
alloc.concat([
|
||||
alloc.keyword("crash"),
|
||||
alloc.reflow(" must be given exacly one message to crash with."),
|
||||
]),
|
||||
]);
|
||||
title = "OVERAPPLIED CRASH".to_string();
|
||||
severity = Severity::RuntimeError;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1375,6 +1375,42 @@ fn to_expr_report<'b>(
|
|||
}
|
||||
}
|
||||
|
||||
Reason::CrashArg => {
|
||||
let this_is = alloc.reflow("The value is");
|
||||
|
||||
let wanted = alloc.concat([
|
||||
alloc.reflow("But I can only "),
|
||||
alloc.keyword("crash"),
|
||||
alloc.reflow(" with messages of type"),
|
||||
]);
|
||||
|
||||
let details = None;
|
||||
|
||||
let lines = [
|
||||
alloc
|
||||
.reflow("This value passed to ")
|
||||
.append(alloc.keyword("crash"))
|
||||
.append(alloc.reflow(" is not a string:")),
|
||||
alloc.region(lines.convert_region(region)),
|
||||
type_comparison(
|
||||
alloc,
|
||||
found,
|
||||
expected_type,
|
||||
ExpectationContext::WhenCondition,
|
||||
add_category(alloc, this_is, &category),
|
||||
wanted,
|
||||
details,
|
||||
),
|
||||
];
|
||||
|
||||
Report {
|
||||
filename,
|
||||
title: "TYPE MISMATCH".to_string(),
|
||||
doc: alloc.stack(lines),
|
||||
severity: Severity::RuntimeError,
|
||||
}
|
||||
}
|
||||
|
||||
Reason::LowLevelOpArg { op, arg_index } => {
|
||||
panic!(
|
||||
"Compiler bug: argument #{} to low-level operation {:?} was the wrong type!",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue