mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
Fix #6240
This commit is contained in:
parent
fe029c85b6
commit
511308d4d3
2 changed files with 88 additions and 3 deletions
|
@ -14426,4 +14426,76 @@ All branches in an `if` must have the same type!
|
||||||
// ),
|
// ),
|
||||||
// @r""
|
// @r""
|
||||||
// );
|
// );
|
||||||
|
|
||||||
|
test_report!(
|
||||||
|
issue_6240_1,
|
||||||
|
indoc!(
|
||||||
|
r"
|
||||||
|
{}.abcde
|
||||||
|
"
|
||||||
|
),
|
||||||
|
@r###"
|
||||||
|
── TYPE MISMATCH in /code/proj/Main.roc ────────────────────────────────────────
|
||||||
|
|
||||||
|
This record doesn’t have a `abcde` field:
|
||||||
|
|
||||||
|
4│ {}.abcde
|
||||||
|
^^^^^^^^
|
||||||
|
|
||||||
|
In fact, it’s a record with no fields at all!
|
||||||
|
"###
|
||||||
|
);
|
||||||
|
|
||||||
|
test_report!(
|
||||||
|
issue_6240_2,
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
("", "").abcde
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
@r###"
|
||||||
|
── TYPE MISMATCH in /code/proj/Main.roc ────────────────────────────────────────
|
||||||
|
|
||||||
|
This expression is used in an unexpected way:
|
||||||
|
|
||||||
|
4│ ("", "").abcde
|
||||||
|
^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
It is a tuple of type:
|
||||||
|
|
||||||
|
(
|
||||||
|
Str,
|
||||||
|
Str,
|
||||||
|
)a
|
||||||
|
|
||||||
|
But you are trying to use it as:
|
||||||
|
|
||||||
|
{ abcde : * }b
|
||||||
|
"###
|
||||||
|
);
|
||||||
|
|
||||||
|
test_report!(
|
||||||
|
issue_6240_3,
|
||||||
|
indoc!(
|
||||||
|
r"
|
||||||
|
{}.0
|
||||||
|
"
|
||||||
|
),
|
||||||
|
@r###"
|
||||||
|
── TYPE MISMATCH in /code/proj/Main.roc ────────────────────────────────────────
|
||||||
|
|
||||||
|
This expression is used in an unexpected way:
|
||||||
|
|
||||||
|
4│ {}.0
|
||||||
|
^^^^
|
||||||
|
|
||||||
|
It is a record of type:
|
||||||
|
|
||||||
|
{}
|
||||||
|
|
||||||
|
But you are trying to use it as:
|
||||||
|
|
||||||
|
(*)b
|
||||||
|
"###
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4978,12 +4978,17 @@ pub fn with_hole<'a>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let struct_index = match index {
|
||||||
|
Some(index) => index,
|
||||||
|
None => return runtime_error(env, "No such field in record"),
|
||||||
|
};
|
||||||
|
|
||||||
compile_struct_like_access(
|
compile_struct_like_access(
|
||||||
env,
|
env,
|
||||||
procs,
|
procs,
|
||||||
layout_cache,
|
layout_cache,
|
||||||
field_layouts,
|
field_layouts,
|
||||||
index.expect("field not in its own type") as _,
|
struct_index,
|
||||||
*loc_expr,
|
*loc_expr,
|
||||||
record_var,
|
record_var,
|
||||||
hole,
|
hole,
|
||||||
|
@ -5076,12 +5081,17 @@ pub fn with_hole<'a>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let tuple_index = match final_index {
|
||||||
|
Some(index) => index as u64,
|
||||||
|
None => return runtime_error(env, "No such index in tuple"),
|
||||||
|
};
|
||||||
|
|
||||||
compile_struct_like_access(
|
compile_struct_like_access(
|
||||||
env,
|
env,
|
||||||
procs,
|
procs,
|
||||||
layout_cache,
|
layout_cache,
|
||||||
field_layouts,
|
field_layouts,
|
||||||
final_index.expect("elem not in its own type") as u64,
|
tuple_index,
|
||||||
*loc_expr,
|
*loc_expr,
|
||||||
tuple_var,
|
tuple_var,
|
||||||
hole,
|
hole,
|
||||||
|
@ -8055,7 +8065,10 @@ fn can_reuse_symbol<'a>(
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.find_map(|(current, (label, _, _))| (label == *field).then_some(current));
|
.find_map(|(current, (label, _, _))| (label == *field).then_some(current));
|
||||||
|
|
||||||
let struct_index = index.expect("field not in its own type");
|
let struct_index = match index {
|
||||||
|
Some(index) => index as u64,
|
||||||
|
None => return NotASymbol,
|
||||||
|
};
|
||||||
|
|
||||||
let struct_symbol = possible_reuse_symbol_or_specialize(
|
let struct_symbol = possible_reuse_symbol_or_specialize(
|
||||||
env,
|
env,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue