From 8f30ea1adcea9e3780806774535bdf2d209f531d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Wed, 3 Apr 2024 13:40:35 -0700 Subject: [PATCH] fix dereferencing non-reference type --- runtime/sema/check_unary_expression.go | 2 +- runtime/tests/checker/reference_test.go | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/runtime/sema/check_unary_expression.go b/runtime/sema/check_unary_expression.go index 07b8998ee9..723179be7b 100644 --- a/runtime/sema/check_unary_expression.go +++ b/runtime/sema/check_unary_expression.go @@ -83,8 +83,8 @@ func (checker *Checker) VisitUnaryExpression(expression *ast.UnaryExpression) Ty ), }, ) - return InvalidType } + return InvalidType } innerType := referenceType.Type diff --git a/runtime/tests/checker/reference_test.go b/runtime/tests/checker/reference_test.go index b06d1caee2..3ddf699fd4 100644 --- a/runtime/tests/checker/reference_test.go +++ b/runtime/tests/checker/reference_test.go @@ -3546,6 +3546,27 @@ func TestCheckDereference(t *testing.T) { `, ) }) + + runInvalidTestCase( + t, + "non-reference", + ` + fun test(foo: Int): AnyStruct { + return *foo + } + `, + ) + + t.Run("invalid type", func(t *testing.T) { + t.Parallel() + + _, err := ParseAndCheck(t, ` + let x = *y + `) + + errs := RequireCheckerErrors(t, err, 1) + assert.IsType(t, &sema.NotDeclaredError{}, errs[0]) + }) } func TestCheckReferenceRequiredTypeAnnotation(t *testing.T) {