diff --git a/types.go b/types.go index ee604c1671..399d247d2c 100644 --- a/types.go +++ b/types.go @@ -1418,6 +1418,12 @@ func (t *FunctionType) Equal(other Type) bool { } } + // Purity + + if t.Purity != otherType.Purity { + return false + } + return t.ReturnType.Equal(otherType.ReturnType) } diff --git a/types_test.go b/types_test.go index d8ab110629..98e2e927f3 100644 --- a/types_test.go +++ b/types_test.go @@ -149,6 +149,16 @@ func TestType_ID(t *testing.T) { }, "fun(Int):String", }, + { + &FunctionType{ + Parameters: []Parameter{ + {Type: IntType}, + }, + ReturnType: StringType, + Purity: FunctionPurityView, + }, + "view fun(Int):String", + }, { &EventType{ QualifiedIdentifier: "Event", @@ -1526,6 +1536,36 @@ func TestTypeEquality(t *testing.T) { target := AnyType assert.False(t, source.Equal(target)) }) + + t.Run("different purity", func(t *testing.T) { + t.Parallel() + + source := &FunctionType{ + Purity: FunctionPurityView, + ReturnType: StringType, + Parameters: []Parameter{ + { + Type: IntType, + }, + { + Type: BoolType, + }, + }, + } + target := &FunctionType{ + Purity: FunctionPurityUnspecified, // default + ReturnType: StringType, + Parameters: []Parameter{ + { + Type: IntType, + }, + { + Type: BoolType, + }, + }, + } + assert.False(t, source.Equal(target)) + }) }) t.Run("reference type", func(t *testing.T) {