diff --git a/src/type_determiner.cc b/src/type_determiner.cc index d118b199e8..23de278722 100644 --- a/src/type_determiner.cc +++ b/src/type_determiner.cc @@ -369,7 +369,7 @@ bool TypeDeterminer::DetermineArrayAccessor( } auto* res = expr->array()->result_type(); - auto* parent_type = res->UnwrapPtrIfNeeded(); + auto* parent_type = res->UnwrapAliasPtrAlias(); ast::type::Type* ret = nullptr; if (parent_type->IsArray()) { ret = parent_type->AsArray()->type(); diff --git a/src/type_determiner_test.cc b/src/type_determiner_test.cc index 3ba3e53fed..15fd077d57 100644 --- a/src/type_determiner_test.cc +++ b/src/type_determiner_test.cc @@ -400,6 +400,31 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Array) { EXPECT_TRUE(ptr->type()->IsF32()); } +TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Alias_Array) { + ast::type::I32Type i32; + ast::type::F32Type f32; + ast::type::ArrayType ary(&f32, 3); + ast::type::AliasType aary("myarrty", &ary); + + auto idx = std::make_unique( + std::make_unique(&i32, 2)); + auto var = std::make_unique( + "my_var", ast::StorageClass::kFunction, &aary); + mod()->AddGlobalVariable(std::move(var)); + + // Register the global + EXPECT_TRUE(td()->Determine()); + + ast::ArrayAccessorExpression acc( + std::make_unique("my_var"), std::move(idx)); + EXPECT_TRUE(td()->DetermineResultType(&acc)); + ASSERT_NE(acc.result_type(), nullptr); + ASSERT_TRUE(acc.result_type()->IsPointer()); + + auto* ptr = acc.result_type()->AsPointer(); + EXPECT_TRUE(ptr->type()->IsF32()); +} + TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Array_Constant) { ast::type::I32Type i32; ast::type::F32Type f32;