Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up intersection types #2757

Merged
merged 2 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion encoding/ccf/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,7 @@ func (d *Decoder) decodeTypeValue(visited *cadenceTypeByCCFTypeID) (cadence.Type
return d.decodeReferenceType(visited, d.decodeTypeValue)

case CBORTagIntersectionTypeValue:
return d.decodeIntersectionType(visited, d.decodeNullableTypeValue, d.decodeTypeValue)
return d.decodeIntersectionType(visited, d.decodeTypeValue)

case CBORTagFunctionTypeValue:
return d.decodeFunctionTypeValue(visited)
Expand Down
3 changes: 1 addition & 2 deletions encoding/ccf/decode_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (d *Decoder) decodeInlineType(types *cadenceTypeByCCFTypeID) (cadence.Type,
return d.decodeReferenceType(types, d.decodeInlineType)

case CBORTagIntersectionType:
return d.decodeIntersectionType(types, d.decodeNullableInlineType, d.decodeInlineType)
return d.decodeIntersectionType(types, d.decodeInlineType)

case CBORTagCapabilityType:
return d.decodeCapabilityType(types, d.decodeNullableInlineType)
Expand Down Expand Up @@ -550,7 +550,6 @@ func (d *Decoder) decodeReferenceType(
// NOTE: decodeTypeFn is responsible for decoding inline-type or type-value.
func (d *Decoder) decodeIntersectionType(
types *cadenceTypeByCCFTypeID,
decodeTypeFn decodeTypeFn,
decodeIntersectionTypeFn decodeTypeFn,
) (cadence.Type, error) {
// types
Expand Down
28 changes: 1 addition & 27 deletions runtime/sema/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -973,33 +973,7 @@ func CheckIntersectionType(
panic(errors.NewUnreachableError())
}

var compositeType *CompositeType

// If the intersection type is a composite type,
// check that the intersections are conformances

if compositeType != nil {

// Prepare a set of all the conformances

conformances := compositeType.EffectiveInterfaceConformanceSet()

for _, intersectedType := range types {
// The intersected type must be an explicit or implicit conformance
// of the composite (intersection type)

if !conformances.Contains(intersectedType) {
report(func(t *ast.IntersectionType) error {
return &InvalidNonConformanceIntersectionError{
Type: intersectedType,
Range: intersectionRanges[intersectedType](t),
}
})
}
}
}

return &IntersectionType{Types: types}
return NewIntersectionType(memoryGauge, types)
}

func (checker *Checker) convertIntersectionType(t *ast.IntersectionType) Type {
Expand Down
2 changes: 1 addition & 1 deletion runtime/tests/interpreter/memory_metering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8589,7 +8589,7 @@ func TestInterpretStaticTypeConversionMetering(t *testing.T) {
assert.Equal(t, uint64(4), meter.getMemory(common.MemoryKindVariableSizedSemaType))
assert.Equal(t, uint64(2), meter.getMemory(common.MemoryKindConstantSizedSemaType))
assert.Equal(t, uint64(2), meter.getMemory(common.MemoryKindOptionalSemaType))
assert.Equal(t, uint64(2), meter.getMemory(common.MemoryKindIntersectionSemaType))
assert.Equal(t, uint64(3), meter.getMemory(common.MemoryKindIntersectionSemaType))
assert.Equal(t, uint64(4), meter.getMemory(common.MemoryKindReferenceSemaType))
assert.Equal(t, uint64(2), meter.getMemory(common.MemoryKindCapabilitySemaType))
})
Expand Down
Loading