Skip to content

Commit 90bd377

Browse files
committed
fix(parser): handle pointer type for array allocation in new operator
Signed-off-by: vibhatsu <maulikbarot2915@gmail.com>
1 parent 8f7f0f6 commit 90bd377

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/parser/parser.y

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3309,7 +3309,14 @@ unary_expression
33093309
| NEW type_name
33103310
{
33113311
TypePtr allocated_type = $2;
3312-
auto ptr_result = type_factory.pointer_from(allocated_type);
3312+
TypePtr pointee_type = allocated_type;
3313+
3314+
if (allocated_type && allocated_type->kind == TypeKind::ARRAY) {
3315+
auto array_type = std::static_pointer_cast<ArrayType>(allocated_type);
3316+
pointee_type = array_type->element_type.type;
3317+
}
3318+
3319+
auto ptr_result = type_factory.pointer_from(pointee_type);
33133320
TypePtr result_type = unwrap_type_or_error(ptr_result, "new expression", @1.begin.line, @1.begin.column);
33143321
$$ = std::make_shared<NewExpr>(allocated_type, result_type);
33153322
}

0 commit comments

Comments
 (0)