mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 08:11:12 +00:00
Using abilities as types is illegal, but we can still compile them
Closes #2881
This commit is contained in:
parent
c0dec1d5bc
commit
80dc50763e
7 changed files with 151 additions and 4 deletions
|
@ -46,6 +46,7 @@ const ABILITY_MEMBER_MISSING_HAS_CLAUSE: &str = "ABILITY MEMBER MISSING HAS CLAU
|
|||
const ABILITY_MEMBER_HAS_EXTRANEOUS_HAS_CLAUSE: &str = "ABILITY MEMBER HAS EXTRANEOUS HAS CLAUSE";
|
||||
const ABILITY_MEMBER_BINDS_MULTIPLE_VARIABLES: &str = "ABILITY MEMBER BINDS MULTIPLE VARIABLES";
|
||||
const ABILITY_NOT_ON_TOPLEVEL: &str = "ABILITY NOT ON TOP-LEVEL";
|
||||
const ABILITY_USED_AS_TYPE: &str = "ABILITY USED AS TYPE";
|
||||
|
||||
pub fn can_problem<'b>(
|
||||
alloc: &'b RocDocAllocator<'b>,
|
||||
|
@ -750,6 +751,34 @@ pub fn can_problem<'b>(
|
|||
title = ABILITY_NOT_ON_TOPLEVEL.to_string();
|
||||
severity = Severity::RuntimeError;
|
||||
}
|
||||
|
||||
Problem::AbilityUsedAsType(suggested_var_name, ability, region) => {
|
||||
doc = alloc.stack(vec![
|
||||
alloc.concat(vec![
|
||||
alloc.reflow("You are attempting to use the ability "),
|
||||
alloc.symbol_unqualified(ability),
|
||||
alloc.reflow(" as a type directly:"),
|
||||
]),
|
||||
alloc.region(lines.convert_region(region)),
|
||||
alloc.reflow(
|
||||
"Abilities can only be used in type annotations to constrain type variables.",
|
||||
),
|
||||
alloc
|
||||
.hint("")
|
||||
.append(alloc.reflow("Perhaps you meant to include a "))
|
||||
.append(alloc.keyword("has"))
|
||||
.append(alloc.reflow(" annotation, like")),
|
||||
alloc.type_block(alloc.concat(vec![
|
||||
alloc.type_variable(suggested_var_name),
|
||||
alloc.space(),
|
||||
alloc.keyword("has"),
|
||||
alloc.space(),
|
||||
alloc.symbol_unqualified(ability),
|
||||
])),
|
||||
]);
|
||||
title = ABILITY_USED_AS_TYPE.to_string();
|
||||
severity = Severity::RuntimeError;
|
||||
}
|
||||
};
|
||||
|
||||
Report {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue