Analyzer lets unions of the same type be assigned to eachother
This commit is contained in:
parent
716306dacb
commit
a1dd782a88
@ -91,7 +91,7 @@ func (this *Tree) canAssign (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// then, check for union assignment
|
// then, check for union assignment
|
||||||
if destination, ok := this.isUnion(destination); ok {
|
if _, ok := this.isUnion(destination); ok {
|
||||||
return this.canAssignUnion(pos, destination, source)
|
return this.canAssignUnion(pos, destination, source)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -296,11 +296,18 @@ func (this *Tree) canAssignInterface (
|
|||||||
// destination.
|
// destination.
|
||||||
func (this *Tree) canAssignUnion (
|
func (this *Tree) canAssignUnion (
|
||||||
pos errors.Position,
|
pos errors.Position,
|
||||||
destination *entity.TypeUnion,
|
destination entity.Type,
|
||||||
source entity.Type,
|
source entity.Type,
|
||||||
) error {
|
) error {
|
||||||
hash := source.Hash()
|
sourceHash := source.Hash()
|
||||||
if _, ok := destination.AllowedMap[hash]; ok { return nil }
|
destinationHash := destination.Hash()
|
||||||
|
union, _ := this.isUnion(destination)
|
||||||
|
|
||||||
|
// check if types are identical
|
||||||
|
if sourceHash == destinationHash { return nil }
|
||||||
|
// check if type is included within the union
|
||||||
|
if _, ok := union.AllowedMap[sourceHash]; ok { return nil }
|
||||||
|
|
||||||
return errors.Errorf (
|
return errors.Errorf (
|
||||||
pos, "%v is not included within union %v",
|
pos, "%v is not included within union %v",
|
||||||
source, destination)
|
source, destination)
|
||||||
|
@ -273,7 +273,7 @@ U: (| Int F64)
|
|||||||
|
|
||||||
func TestAssignmentUnionErrNotListed (test *testing.T) {
|
func TestAssignmentUnionErrNotListed (test *testing.T) {
|
||||||
testStringErr (test,
|
testStringErr (test,
|
||||||
"I64 is not included within union (| Int F64)", 5, 8,
|
"I64 is not included within union U", 5, 8,
|
||||||
`
|
`
|
||||||
U: (| Int F64)
|
U: (| Int F64)
|
||||||
[main] = {
|
[main] = {
|
||||||
|
Loading…
Reference in New Issue
Block a user