mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 12:18:19 +00:00
Report import lowercase alias
This commit is contained in:
parent
97ed8fdbbd
commit
f81985533c
4 changed files with 51 additions and 6 deletions
|
@ -4987,6 +4987,25 @@ mod test_reporting {
|
|||
"###
|
||||
);
|
||||
|
||||
test_report!(
|
||||
lowercase_import_alias,
|
||||
indoc!(
|
||||
r"
|
||||
import svg.Path as path
|
||||
"
|
||||
),
|
||||
@r###"
|
||||
── LOWERCASE ALIAS in tmp/lowercase_import_alias/Test.roc ──────────────────────
|
||||
|
||||
This import is using a lowercase alias:
|
||||
|
||||
4│ import svg.Path as path
|
||||
^^^^
|
||||
|
||||
Module names and aliases must start with an uppercase letter.
|
||||
"###
|
||||
);
|
||||
|
||||
test_report!(
|
||||
ingested_file_import_ann_syntax_err,
|
||||
indoc!(
|
||||
|
|
|
@ -9,8 +9,7 @@ use crate::blankspace::{
|
|||
space0_before_optional_after, space0_e, spaces, spaces_around, spaces_before,
|
||||
};
|
||||
use crate::ident::{
|
||||
integer_ident, lowercase_ident, parse_ident, unqualified_ident, uppercase_ident, Accessor,
|
||||
Ident, Suffix,
|
||||
integer_ident, lowercase_ident, parse_ident, unqualified_ident, Accessor, Ident, Suffix,
|
||||
};
|
||||
use crate::module::module_name_help;
|
||||
use crate::parser::{
|
||||
|
@ -997,10 +996,20 @@ fn import_as<'a>(
|
|||
EImport::IndentAs,
|
||||
EImport::IndentAlias
|
||||
),
|
||||
item: loc!(map!(
|
||||
specialize_err(|_, pos| EImport::Alias(pos), uppercase_ident()),
|
||||
ImportAlias::new
|
||||
))
|
||||
item: then(
|
||||
specialize_err(|_, pos| EImport::Alias(pos), loc!(unqualified_ident())),
|
||||
|_arena, state, _progress, loc_ident| {
|
||||
match loc_ident.value.chars().next() {
|
||||
Some(first) if first.is_uppercase() => Ok((
|
||||
MadeProgress,
|
||||
loc_ident.map(|ident| ImportAlias::new(ident)),
|
||||
state,
|
||||
)),
|
||||
Some(_) => Err((MadeProgress, EImport::LowercaseAlias(loc_ident.region))),
|
||||
None => Err((MadeProgress, EImport::Alias(state.pos()))),
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -534,6 +534,7 @@ pub enum EImport<'a> {
|
|||
As(Position),
|
||||
IndentAlias(Position),
|
||||
Alias(Position),
|
||||
LowercaseAlias(Region),
|
||||
IndentExposing(Position),
|
||||
Exposing(Position),
|
||||
ExposingListStart(Position),
|
||||
|
|
|
@ -1514,7 +1514,23 @@ fn to_import_report<'a>(
|
|||
alloc.reflow(" keyword, so I was expecting to see an alias next."),
|
||||
]),
|
||||
),
|
||||
LowercaseAlias(region) => {
|
||||
let surroundings = Region::new(start, region.end());
|
||||
let region = lines.convert_region(*region);
|
||||
|
||||
let doc = alloc.stack([
|
||||
alloc.reflow(r"This import is using a lowercase alias:"),
|
||||
alloc.region_with_subregion(lines.convert_region(surroundings), region),
|
||||
alloc.reflow(r"Module names and aliases must start with an uppercase letter."),
|
||||
]);
|
||||
|
||||
Report {
|
||||
filename,
|
||||
doc,
|
||||
title: "LOWERCASE ALIAS".to_string(),
|
||||
severity: Severity::RuntimeError,
|
||||
}
|
||||
}
|
||||
Annotation(problem, pos) => to_type_report(alloc, lines, filename, problem, *pos),
|
||||
Space(problem, pos) => to_space_report(alloc, lines, filename, problem, *pos),
|
||||
ExposingListStart(_) => todo!(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue