Each of the individual types named in the union type must be unique.
Chris Pressey
3 years ago
1066 | 1066 | | } |
1067 | 1067 | = ok |
1068 | 1068 | |
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 | |
1081 | 1081 | |
1082 | 1082 | Cannot promote a union type to itself. |
1083 | 1083 |
28 | 28 | Other backends (Python? Java? CIL? Scheme?) |
29 | 29 | |
30 | 30 | ### Design ### |
31 | ||
32 | Each of the individual types named in the union type must be unique. | |
33 | 31 | |
34 | 32 | Promote union type to bigger union type (e.g. `string|int` => `string|int|void`) |
35 | 33 |
150 | 150 | [self.type_of(c) for c in ast.children[1:]], return_type |
151 | 151 | ) |
152 | 152 | 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) | |
154 | 160 | elif ast.tag == 'StructType': |
155 | 161 | ast.type = Struct(ast.value) |
156 | 162 | elif ast.tag == 'VarRef': |