Implement typed dictionaries

This commit is contained in:
Thaddeus Crews 2023-06-24 13:03:28 -05:00
parent 906a4e9db9
commit 9853a69144
No known key found for this signature in database
GPG key ID: 62181B86FE9E5D84
86 changed files with 3071 additions and 193 deletions

View file

@ -0,0 +1,3 @@
func test():
for key: int in { "a": 1 }:
print(key)

View file

@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Cannot include a value of type "String" as "int".

View file

@ -0,0 +1,4 @@
func test():
var differently: Dictionary[float, float] = { 1.0: 0.0 }
var typed: Dictionary[int, int] = differently
print('not ok')

View file

@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Cannot assign a value of type Dictionary[float, float] to variable "typed" with specified type Dictionary[int, int].

View file

@ -0,0 +1,2 @@
func test():
const dict: Dictionary[int, int] = { "Hello": "World" }

View file

@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Cannot include a value of type "String" as "int".

View file

@ -0,0 +1,4 @@
func test():
var unconvertible := 1
var typed: Dictionary[Object, Object] = { unconvertible: unconvertible }
print('not ok')

View file

@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Cannot have a key of type "int" in a dictionary of type "Dictionary[Object, Object]".

View file

@ -0,0 +1,7 @@
func expect_typed(typed: Dictionary[int, int]):
print(typed.size())
func test():
var differently: Dictionary[float, float] = { 1.0: 0.0 }
expect_typed(differently)
print('not ok')

View file

@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Invalid argument for "expect_typed()" function: argument 1 should be "Dictionary[int, int]" but is "Dictionary[float, float]".