Skip to content

Commit

Permalink
Revert "gate new behaviour (errors for all invalid type cases) behind…
Browse files Browse the repository at this point in the history
… a feature flag"

This reverts commit 3e2ecc99b3a819ffb123723f62777a2655bbbae6.
  • Loading branch information
turbolent committed Nov 21, 2024
1 parent b4f27e1 commit aecd31a
Show file tree
Hide file tree
Showing 16 changed files with 340 additions and 750 deletions.
9 changes: 2 additions & 7 deletions runtime/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"time"

"go.opentelemetry.io/otel/attribute"
"golang.org/x/mod/semver"

"github.com/onflow/cadence"
"github.com/onflow/cadence/runtime/activations"
Expand Down Expand Up @@ -1462,9 +1461,6 @@ func (e *interpreterEnvironment) newValidateAccountCapabilitiesPublishHandler()
}
}

// TODO:
const MinimumRequiredVersionForInvalidTypeErrorFixes = "v1.0.3"

func (e *interpreterEnvironment) configureVersionedFeatures() {
var (
minimumRequiredVersion string
Expand All @@ -1477,7 +1473,6 @@ func (e *interpreterEnvironment) configureVersionedFeatures() {
panic(err)
}

e.CheckerConfig.InvalidTypeErrorFixesEnabled =
minimumRequiredVersion != "" &&
semver.Compare(MinimumRequiredVersionForInvalidTypeErrorFixes, minimumRequiredVersion) >= 0
// No feature flags yet
_ = minimumRequiredVersion
}
85 changes: 30 additions & 55 deletions runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11553,66 +11553,41 @@ func TestRuntimeInvocationReturnTypeInferenceFailure(t *testing.T) {

t.Parallel()

test := func(invalidTypeErrorFixesEnabled bool) {

name := fmt.Sprintf(
"error fixes enabled: %v",
invalidTypeErrorFixesEnabled,
)

t.Run(name, func(t *testing.T) {
t.Parallel()

address := common.MustBytesToAddress([]byte{0x1})

runtimeInterface := &TestRuntimeInterface{
Storage: NewTestLedger(nil, nil),
OnGetSigningAccounts: func() ([]common.Address, error) {
return []common.Address{address}, nil
},
OnMinimumRequiredVersion: func() (string, error) {
if invalidTypeErrorFixesEnabled {
return MinimumRequiredVersionForInvalidTypeErrorFixes, nil
}
return "", nil
},
}
address := common.MustBytesToAddress([]byte{0x1})

runtime := NewTestInterpreterRuntime()
newRuntimeInterface := func() Interface {

nextTransactionLocation := NewTransactionLocationGenerator()
return &TestRuntimeInterface{
Storage: NewTestLedger(nil, nil),
OnGetSigningAccounts: func() ([]common.Address, error) {
return []common.Address{address}, nil
},
}
}

tx := []byte(`
transaction{
prepare(signer: auth(Storage) &Account){
let functions = [signer.storage.save].reverse()
}
}
`)
runtime := NewTestInterpreterRuntime()

err := runtime.ExecuteTransaction(
Script{
Source: tx,
},
Context{
Interface: runtimeInterface,
Location: nextTransactionLocation(),
},
)
nextTransactionLocation := NewTransactionLocationGenerator()

RequireError(t, err)
tx := []byte(`
transaction{
prepare(signer: auth(Storage) &Account){
let functions = [signer.storage.save].reverse()
}
}
`)

if invalidTypeErrorFixesEnabled {
var typeErr *sema.InvocationTypeInferenceError
require.ErrorAs(t, err, &typeErr)
} else {
var transferErr interpreter.ValueTransferTypeError
require.ErrorAs(t, err, &transferErr)
}
})
}
err := runtime.ExecuteTransaction(
Script{
Source: tx,
},
Context{
Interface: newRuntimeInterface(),
Location: nextTransactionLocation(),
},
)
RequireError(t, err)

for _, invalidTypeErrorFixesEnabled := range []bool{true, false} {
test(invalidTypeErrorFixesEnabled)
}
var typeErr *sema.InvocationTypeInferenceError
require.ErrorAs(t, err, &typeErr)
}
42 changes: 18 additions & 24 deletions runtime/sema/check_invocation_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,14 +503,12 @@ func (checker *Checker) checkInvocation(

returnType = functionType.ReturnTypeAnnotation.Type.Resolve(typeArguments)
if returnType == nil {
if checker.Config.InvalidTypeErrorFixesEnabled {
checker.report(&InvocationTypeInferenceError{
Range: ast.NewRangeFromPositioned(
checker.memoryGauge,
invocationExpression,
),
})
}
checker.report(&InvocationTypeInferenceError{
Range: ast.NewRangeFromPositioned(
checker.memoryGauge,
invocationExpression,
),
})

returnType = InvalidType
}
Expand Down Expand Up @@ -607,14 +605,12 @@ func (checker *Checker) checkInvocationRequiredArgument(
parameterType = parameterType.Resolve(typeParameters)
// If the type parameter could not be resolved, use the invalid type.
if parameterType == nil {
if checker.Config.InvalidTypeErrorFixesEnabled {
checker.report(&InvocationTypeInferenceError{
Range: ast.NewRangeFromPositioned(
checker.memoryGauge,
argument.Expression,
),
})
}
checker.report(&InvocationTypeInferenceError{
Range: ast.NewRangeFromPositioned(
checker.memoryGauge,
argument.Expression,
),
})
parameterType = InvalidType
}
}
Expand Down Expand Up @@ -690,14 +686,12 @@ func (checker *Checker) checkInvocationRequiredArgument(
parameterType = parameterType.Resolve(typeParameters)
// If the type parameter could not be resolved, use the invalid type.
if parameterType == nil {
if checker.Config.InvalidTypeErrorFixesEnabled {
checker.report(&InvocationTypeInferenceError{
Range: ast.NewRangeFromPositioned(
checker.memoryGauge,
argument.Expression,
),
})
}
checker.report(&InvocationTypeInferenceError{
Range: ast.NewRangeFromPositioned(
checker.memoryGauge,
argument.Expression,
),
})
parameterType = InvalidType
}
}
Expand Down
16 changes: 5 additions & 11 deletions runtime/sema/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,16 +886,12 @@ func (checker *Checker) ConvertType(t ast.Type) Type {
case *ast.InstantiationType:
return checker.convertInstantiationType(t)

case nil:
if checker.Config.InvalidTypeErrorFixesEnabled {
checker.report(&UnconvertableTypeError{
Range: ast.NewRangeFromPositioned(checker.memoryGauge, t),
})
}
default:
checker.report(&UnconvertableTypeError{
Range: ast.NewRangeFromPositioned(checker.memoryGauge, t),
})
return InvalidType
}

panic(&astTypeConversionError{invalidASTType: t})
}

func CheckIntersectionType(
Expand Down Expand Up @@ -2615,9 +2611,7 @@ func (checker *Checker) visitExpressionWithForceType(

actualType = ast.AcceptExpression[Type](expr, checker)

if checker.Config.InvalidTypeErrorFixesEnabled {
checker.checkErrorsForInvalidExpressionTypes(actualType, expectedType)
}
checker.checkErrorsForInvalidExpressionTypes(actualType, expectedType)

if checker.Config.ExtendedElaborationEnabled {
checker.Elaboration.SetExpressionTypes(
Expand Down
2 changes: 0 additions & 2 deletions runtime/sema/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,4 @@ type Config struct {
AllowStaticDeclarations bool
// AttachmentsEnabled determines if attachments are enabled
AttachmentsEnabled bool
// InvalidTypeErrorFixesEnabled determines if errors for invalid type errors are reported
InvalidTypeErrorFixesEnabled bool
}
10 changes: 0 additions & 10 deletions runtime/sema/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,6 @@ func ErrorMessageExpectedActualTypes(
return
}

// astTypeConversionError

type astTypeConversionError struct {
invalidASTType ast.Type
}

func (e *astTypeConversionError) Error() string {
return fmt.Sprintf("cannot convert unsupported AST type: %#+v", e.invalidASTType)
}

// unsupportedOperation

type unsupportedOperation struct {
Expand Down
Loading

0 comments on commit aecd31a

Please sign in to comment.