diff --git a/src/tint/resolver/resolver.cc b/src/tint/resolver/resolver.cc index 19571a7bff..58050b9f17 100644 --- a/src/tint/resolver/resolver.cc +++ b/src/tint/resolver/resolver.cc @@ -3115,13 +3115,14 @@ sem::Expression* Resolver::Identifier(const ast::IdentifierExpression* expr) { } sem::ValueExpression* Resolver::MemberAccessor(const ast::MemberAccessorExpression* expr) { - auto* structure = sem_.TypeOf(expr->object); - auto* storage_ty = structure->UnwrapRef(); auto* object = sem_.GetVal(expr->object); if (!object) { return nullptr; } + auto* object_ty = object->Type(); + auto* storage_ty = object_ty->UnwrapRef(); + auto* root_ident = object->RootIdentifier(); const type::Type* ty = nullptr; @@ -3152,7 +3153,7 @@ sem::ValueExpression* Resolver::MemberAccessor(const ast::MemberAccessorExpressi ty = member->Type(); // If we're extracting from a reference, we return a reference. - if (auto* ref = structure->As()) { + if (auto* ref = object_ty->As()) { ty = builder_->create(ty, ref->AddressSpace(), ref->Access()); } @@ -3221,7 +3222,7 @@ sem::ValueExpression* Resolver::MemberAccessor(const ast::MemberAccessorExpressi // A single element swizzle is just the type of the vector. ty = vec->type(); // If we're extracting from a reference, we return a reference. - if (auto* ref = structure->As()) { + if (auto* ref = object_ty->As()) { ty = builder_->create(ty, ref->AddressSpace(), ref->Access()); } } else { diff --git a/src/tint/resolver/resolver_test.cc b/src/tint/resolver/resolver_test.cc index a601ef048a..5df2fae4be 100644 --- a/src/tint/resolver/resolver_test.cc +++ b/src/tint/resolver/resolver_test.cc @@ -1239,6 +1239,15 @@ TEST_F(ResolverTest, Function_WorkgroupSize_Mixed) { EXPECT_EQ(func_sem->WorkgroupSize()[2], 3u); } +TEST_F(ResolverTest, Expr_MemberAccessor_Type) { + auto* mem = MemberAccessor(Ident(Source{{12, 34}}, "f32"), "member"); + WrapInFunction(mem); + + EXPECT_FALSE(r()->Resolve()) << r()->error(); + EXPECT_EQ(r()->error(), R"(12:34 error: cannot use type 'f32' as value +12:34 note: are you missing '()' for value constructor?)"); +} + TEST_F(ResolverTest, Expr_MemberAccessor_Struct) { auto* st = Structure( "S", utils::Vector{Member("first_member", ty.i32()), Member("second_member", ty.f32())}); diff --git a/src/tint/resolver/sem_helper.cc b/src/tint/resolver/sem_helper.cc index 2357ce1dd7..dd2341fd2a 100644 --- a/src/tint/resolver/sem_helper.cc +++ b/src/tint/resolver/sem_helper.cc @@ -105,8 +105,7 @@ void SemHelper::ErrorExpectedValueExpr(const sem::Expression* expr) const { ErrorUnexpectedExprKind(expr, "value"); if (auto* ty_expr = expr->As()) { if (auto* ident = ty_expr->Declaration()->As()) { - AddNote("are you missing '()' for value constructor?", - Source{{ident->source.range.end}}); + AddNote("are you missing '()' for value constructor?", ident->source.End()); } } }