mirror of
https://github.com/odin-lang/Odin.git
synced 2026-08-26 15:01:31 +00:00
Merge pull request #7418 from kalsprite/type_call_null_arg
Fix compiler segfault on a bare `..` in a type position call
This commit is contained in:
@@ -8309,6 +8309,10 @@ gb_internal CallArgumentError check_polymorphic_record_type(CheckerContext *c, O
|
||||
|
||||
bool named_fields = false;
|
||||
{
|
||||
if (ce->ellipsis.pos.line != 0) {
|
||||
error(ce->ellipsis, "Invalid use of '..' in a polymorphic type call");
|
||||
}
|
||||
|
||||
// NOTE(bill, 2019-10-26): Allow a cycle in the parameters but not in the fields themselves
|
||||
auto prev_type_path = c->type_path;
|
||||
|
||||
@@ -8347,11 +8351,6 @@ gb_internal CallArgumentError check_polymorphic_record_type(CheckerContext *c, O
|
||||
check_expr_or_type(c, &operands[i], fv->value);
|
||||
}
|
||||
|
||||
bool vari_expand = (ce->ellipsis.pos.line != 0);
|
||||
if (vari_expand) {
|
||||
error(ce->ellipsis, "Invalid use of '..' in a polymorphic type call'");
|
||||
}
|
||||
|
||||
} else {
|
||||
operands = array_make<Operand>(temporary_allocator(), 0, 2*ce->args.count);
|
||||
|
||||
|
||||
@@ -3660,7 +3660,10 @@ gb_internal Ast *parse_call_expr(AstFile *f, Ast *operand) {
|
||||
} else if (seen_ellipsis) {
|
||||
syntax_error(arg, "Positional arguments are not allowed after '..'");
|
||||
}
|
||||
array_add(&args, arg);
|
||||
if (arg != nullptr) {
|
||||
// `parse_atom_expr` returns nothing when `allow_type` is set and there is no operand
|
||||
array_add(&args, arg);
|
||||
}
|
||||
|
||||
if (ellipsis.pos.line != 0) {
|
||||
seen_ellipsis = true;
|
||||
|
||||
@@ -42,6 +42,7 @@ set COMMON=-define:ODIN_TEST_FANCY=false -file -vet -strict-style -ignore-unused
|
||||
..\..\..\odin check ..\test_issue_6979.odin -no-entry-point %COMMON% || exit /b
|
||||
..\..\..\odin check ..\test_issue_7012.odin -no-entry-point %COMMON% || exit /b
|
||||
..\..\..\odin check ..\test_issue_7260.odin -no-entry-point %COMMON% || exit /b
|
||||
..\..\..\odin check ..\test_issue_ellipsis_type_call.odin -no-entry-point %COMMON% 2>&1 | find /c "Error:" | findstr /x "10" || exit /b
|
||||
..\..\..\odin check ..\test_issue_foreign_redeclaration.odin -no-entry-point %COMMON% || exit /b
|
||||
..\..\..\odin check ..\test_issue_foreign_redeclaration_mismatch.odin -no-entry-point %COMMON% 2>&1 | find /c "Error:" | findstr /x "1" || exit /b
|
||||
..\..\..\odin build ..\test_issue_7037.odin %COMMON% -o:none || exit /b
|
||||
|
||||
@@ -102,6 +102,13 @@ else
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ $($ODIN check ../test_issue_ellipsis_type_call.odin -no-entry-point $COMMON_CHECK 2>&1 >/dev/null | grep -c "Error:") -eq 10 ]]; then
|
||||
echo "SUCCESSFUL 1/1"
|
||||
else
|
||||
echo "SUCCESSFUL 0/1"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ $($ODIN build ../test_issue_7108.odin $COMMON 2>&1 >/dev/null | grep -c "Error:") -eq 2 ]]; then
|
||||
echo "SUCCESSFUL 1/1"
|
||||
else
|
||||
|
||||
45
tests/issues/test_issue_ellipsis_type_call.odin
Normal file
45
tests/issues/test_issue_ellipsis_type_call.odin
Normal file
@@ -0,0 +1,45 @@
|
||||
// Tests that a bare `..` in a type position call is rejected rather than left as a
|
||||
// null argument for the checker to walk off of.
|
||||
package test_issues
|
||||
|
||||
Foo :: struct($T: typeid) {
|
||||
x: T,
|
||||
}
|
||||
|
||||
S :: struct {
|
||||
a: int,
|
||||
}
|
||||
|
||||
bare :: proc() {
|
||||
v: Foo(..)
|
||||
_ = v
|
||||
}
|
||||
|
||||
named_then_bare :: proc() {
|
||||
v: Foo(T = int, ..)
|
||||
_ = v
|
||||
}
|
||||
|
||||
bare_then_named :: proc() {
|
||||
v: Foo(.., T = int)
|
||||
_ = v
|
||||
}
|
||||
|
||||
positional_then_bare :: proc() {
|
||||
v: Foo(int, ..)
|
||||
_ = v
|
||||
}
|
||||
|
||||
conversion_to_struct :: proc() {
|
||||
v: S(..)
|
||||
_ = v
|
||||
}
|
||||
|
||||
conversion_to_builtin :: proc() {
|
||||
v: int(..)
|
||||
_ = v
|
||||
}
|
||||
|
||||
result_type :: proc() -> Foo(..) {
|
||||
return {}
|
||||
}
|
||||
Reference in New Issue
Block a user