git @ Cat's Eye Technologies Castile / 1fc49f5
Each of the individual types named in the union type must be unique. Chris Pressey 3 years ago
3 changed file(s) with 19 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
10661066 | }
10671067 = ok
10681068
1069 Each of the individual types named in the union type must be unique. (TODO)
1070
1071 /| fun foo(a, b: integer|string) {
1072 /| print("ok")
1073 /| }
1074 /| fun main() {
1075 /| a = 20;
1076 /| b = 30;
1077 /| c = a + b as integer|integer|string
1078 /| foo(a, c)
1079 /| }
1080 /? bad union type
1069 Each of the individual types named in the union type must be unique.
1070
1071 | fun foo(a, b: integer|string) {
1072 | print("ok")
1073 | }
1074 | fun main() {
1075 | a = 20;
1076 | b = 30;
1077 | c = a + b as integer|integer|string
1078 | foo(a, c)
1079 | }
1080 ? bad union type
10811081
10821082 Cannot promote a union type to itself.
10831083
2828 Other backends (Python? Java? CIL? Scheme?)
2929
3030 ### Design ###
31
32 Each of the individual types named in the union type must be unique.
3331
3432 Promote union type to bigger union type (e.g. `string|int` => `string|int|void`)
3533
150150 [self.type_of(c) for c in ast.children[1:]], return_type
151151 )
152152 elif ast.tag == 'UnionType':
153 ast.type = Union([self.type_of(c) for c in ast.children])
153 types = []
154 for c in ast.children:
155 type_ = self.type_of(c)
156 if type_ in types:
157 raise CastileTypeError("bad union type")
158 types.append(type_)
159 ast.type = Union(types)
154160 elif ast.tag == 'StructType':
155161 ast.type = Struct(ast.value)
156162 elif ast.tag == 'VarRef':