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
|
||||
if destination, ok := this.isUnion(destination); ok {
|
||||
if _, ok := this.isUnion(destination); ok {
|
||||
return this.canAssignUnion(pos, destination, source)
|
||||
}
|
||||
|
||||
@ -295,12 +295,19 @@ func (this *Tree) canAssignInterface (
|
||||
// analyzed source type, and determines whether source can be assigned to
|
||||
// destination.
|
||||
func (this *Tree) canAssignUnion (
|
||||
pos errors.Position,
|
||||
destination *entity.TypeUnion,
|
||||
source entity.Type,
|
||||
pos errors.Position,
|
||||
destination entity.Type,
|
||||
source entity.Type,
|
||||
) error {
|
||||
hash := source.Hash()
|
||||
if _, ok := destination.AllowedMap[hash]; ok { return nil }
|
||||
sourceHash := source.Hash()
|
||||
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 (
|
||||
pos, "%v is not included within union %v",
|
||||
source, destination)
|
||||
|
@ -273,7 +273,7 @@ U: (| Int F64)
|
||||
|
||||
func TestAssignmentUnionErrNotListed (test *testing.T) {
|
||||
testStringErr (test,
|
||||
"I64 is not included within union (| Int F64)", 5, 8,
|
||||
"I64 is not included within union U", 5, 8,
|
||||
`
|
||||
U: (| Int F64)
|
||||
[main] = {
|
||||
|
Loading…
Reference in New Issue
Block a user