Skip to content

Commit

Permalink
Merge pull request #3339 from onflow/supun/port-229
Browse files Browse the repository at this point in the history
Check dictionary keys when checking the ability for dereferencing
  • Loading branch information
SupunS authored May 14, 2024
2 parents 25c2174 + db70473 commit 282c93c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion runtime/sema/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -7380,7 +7380,8 @@ func IsPrimitiveOrContainerOfPrimitive(referencedType Type) bool {
return IsPrimitiveOrContainerOfPrimitive(ty.Type)

case *DictionaryType:
return IsPrimitiveOrContainerOfPrimitive(ty.ValueType)
return IsPrimitiveOrContainerOfPrimitive(ty.KeyType) &&
IsPrimitiveOrContainerOfPrimitive(ty.ValueType)

default:
return ty.IsPrimitiveType()
Expand Down
17 changes: 17 additions & 0 deletions runtime/tests/checker/reference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3512,6 +3512,23 @@ func TestCheckDereference(t *testing.T) {
}
`,
)

// Dictionaries with composite typed keys cannot be dereferenced.
runInvalidTestCase(
t,
"{Enum: Int}",
`
access(all) enum E:Int {
access(all) case first
}
access(all) fun main() {
var dict = {E.first: 0}
var ref = &dict as &{E: Int}
var deref = *ref
}
`,
)
})

runInvalidTestCase(
Expand Down

0 comments on commit 282c93c

Please sign in to comment.