Skip to content

Commit 1bbe7e2

Browse files
committed
test invalid function type subtyping: grant of additional entitlements for reference
1 parent ab53cbd commit 1bbe7e2

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

sema/function_test.go

+30
Original file line numberDiff line numberDiff line change
@@ -648,3 +648,33 @@ func TestCheckViewFunctionWithErrors(t *testing.T) {
648648
assert.IsType(t, &sema.PurityError{}, errs[1])
649649
})
650650
}
651+
652+
func TestCheckInvalidFunctionSubtyping(t *testing.T) {
653+
654+
t.Parallel()
655+
656+
_, err := ParseAndCheck(t, `
657+
resource R {}
658+
659+
entitlement E
660+
661+
fun test() {
662+
var f: fun (&R) = fun(ref: &R) {}
663+
f = fun(ref: auth(E) &R) {}
664+
}
665+
`)
666+
errs := RequireCheckerErrors(t, err, 1)
667+
assert.IsType(t, &sema.TypeMismatchError{}, errs[0])
668+
669+
var errTypeMismatch *sema.TypeMismatchError
670+
require.ErrorAs(t, err, &errTypeMismatch)
671+
assert.Equal(t, 8, errTypeMismatch.StartPos.Line)
672+
assert.Equal(t,
673+
common.TypeID("fun(&S.test.R):Void"),
674+
errTypeMismatch.ExpectedType.ID(),
675+
)
676+
assert.Equal(t,
677+
common.TypeID("fun(auth(S.test.E)&S.test.R):Void"),
678+
errTypeMismatch.ActualType.ID(),
679+
)
680+
}

0 commit comments

Comments
 (0)