mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 11:52:19 +00:00
Capture import params location for better errors
This commit is contained in:
parent
f0fe0a3ea6
commit
90c7745989
6 changed files with 24 additions and 16 deletions
|
@ -3155,13 +3155,14 @@ fn to_pending_value_def<'a>(
|
|||
let params = module_import.params.and_then(|params| {
|
||||
let name_str = name_with_alias.as_str();
|
||||
|
||||
// todo(agus): params specific loc
|
||||
match scope.introduce_str(format!("#{name_str}").as_str(), region) {
|
||||
let params_region = params.params.region;
|
||||
|
||||
match scope.introduce_str(format!("#{name_str}").as_str(), params_region) {
|
||||
Ok(sym) => {
|
||||
params_sym = Some(sym);
|
||||
|
||||
let loc_pattern = Loc::at(region, Pattern::Identifier(sym));
|
||||
Some((sym, loc_pattern, params.params))
|
||||
let loc_pattern = Loc::at(params_region, Pattern::Identifier(sym));
|
||||
Some((sym, loc_pattern, params.params.value))
|
||||
},
|
||||
Err(_) => {
|
||||
// Ignore conflict, it will be handled as a duplicate import
|
||||
|
|
|
@ -140,7 +140,9 @@ fn desugar_value_def<'a>(
|
|||
let desugared_params =
|
||||
params.map(|ModuleImportParams { before, params }| ModuleImportParams {
|
||||
before,
|
||||
params: desugar_field_collection(arena, params, src, line_info, module_path),
|
||||
params: params.map(|params| {
|
||||
desugar_field_collection(arena, *params, src, line_info, module_path)
|
||||
}),
|
||||
});
|
||||
|
||||
ModuleImport(roc_parse::ast::ModuleImport {
|
||||
|
|
|
@ -252,14 +252,14 @@ impl<'a> Formattable for ModuleImportParams<'a> {
|
|||
fn is_multiline(&self) -> bool {
|
||||
let ModuleImportParams { before, params } = self;
|
||||
|
||||
!before.is_empty() || is_collection_multiline(params)
|
||||
!before.is_empty() || is_collection_multiline(¶ms.value)
|
||||
}
|
||||
|
||||
fn format_with_options(&self, buf: &mut Buf, _parens: Parens, newlines: Newlines, indent: u16) {
|
||||
let ModuleImportParams { before, params } = self;
|
||||
|
||||
fmt_default_spaces(buf, before, indent);
|
||||
fmt_collection(buf, indent, Braces::Curly, *params, newlines);
|
||||
fmt_collection(buf, indent, Braces::Curly, params.value, newlines);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1031,7 +1031,7 @@ impl<'a, 'b> Iterator for RecursiveValueDefIter<'a, 'b> {
|
|||
params,
|
||||
}) => {
|
||||
if let Some(ModuleImportParams { before: _, params }) = params {
|
||||
for loc_assigned_field in params.items {
|
||||
for loc_assigned_field in params.value.items {
|
||||
if let Some(expr) = loc_assigned_field.value.value() {
|
||||
self.push_pending_from_expr(&expr.value);
|
||||
}
|
||||
|
@ -1079,7 +1079,7 @@ pub struct ModuleImport<'a> {
|
|||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct ModuleImportParams<'a> {
|
||||
pub before: &'a [CommentOrNewline<'a>],
|
||||
pub params: Collection<'a, Loc<AssignedField<'a, Expr<'a>>>>,
|
||||
pub params: Loc<Collection<'a, Loc<AssignedField<'a, Expr<'a>>>>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
|
|
|
@ -993,9 +993,11 @@ fn import_params<'a>() -> impl Parser<'a, ModuleImportParams<'a>, EImportParams<
|
|||
then(
|
||||
and(
|
||||
backtrackable(space0_e(EImportParams::Indent)),
|
||||
specialize_err(EImportParams::Record, record_help()),
|
||||
specialize_err(EImportParams::Record, loc(record_help())),
|
||||
),
|
||||
|arena, state, _, (before, record): (_, RecordHelp<'a>)| {
|
||||
|arena, state, _, (before, loc_record): (_, Loc<RecordHelp<'a>>)| {
|
||||
let record = loc_record.value;
|
||||
|
||||
if let Some(update) = record.update {
|
||||
return Err((
|
||||
MadeProgress,
|
||||
|
@ -1013,7 +1015,10 @@ fn import_params<'a>() -> impl Parser<'a, ModuleImportParams<'a>, EImportParams<
|
|||
}
|
||||
})?;
|
||||
|
||||
let import_params = ModuleImportParams { before, params };
|
||||
let import_params = ModuleImportParams {
|
||||
before,
|
||||
params: Loc::at(loc_record.region, params),
|
||||
};
|
||||
|
||||
Ok((MadeProgress, import_params, state))
|
||||
},
|
||||
|
|
|
@ -44,7 +44,7 @@ Defs {
|
|||
params: Some(
|
||||
ModuleImportParams {
|
||||
before: [],
|
||||
params: [
|
||||
params: @15-29 [
|
||||
@17-21 LabelOnly(
|
||||
@17-21 "echo",
|
||||
),
|
||||
|
@ -70,7 +70,7 @@ Defs {
|
|||
params: Some(
|
||||
ModuleImportParams {
|
||||
before: [],
|
||||
params: [
|
||||
params: @42-60 [
|
||||
@44-48 LabelOnly(
|
||||
@44-48 "echo",
|
||||
),
|
||||
|
@ -101,7 +101,7 @@ Defs {
|
|||
params: Some(
|
||||
ModuleImportParams {
|
||||
before: [],
|
||||
params: [
|
||||
params: @73-91 [
|
||||
@75-79 LabelOnly(
|
||||
@75-79 "echo",
|
||||
),
|
||||
|
@ -143,7 +143,7 @@ Defs {
|
|||
params: Some(
|
||||
ModuleImportParams {
|
||||
before: [],
|
||||
params: [
|
||||
params: @109-123 [
|
||||
@111-115 LabelOnly(
|
||||
@111-115 "echo",
|
||||
),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue