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 types in cadence package #1204

Merged
merged 5 commits into from
Nov 5, 2021
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/json/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ func decodeFunctionType(returnValue, parametersValue, id interface{}) cadence.Ty
parameters := decodeParamTypes(toSlice(parametersValue))
returnType := decodeType(returnValue)

return cadence.Function{
return cadence.FunctionType{
Parameters: parameters,
ReturnType: returnType,
}.WithID(toString(id))
Expand Down
5 changes: 2 additions & 3 deletions encoding/json/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ func prepareComposite(kind, id string, fieldTypes []cadence.Field, fields []cade
nonFunctionFieldTypes := make([]cadence.Field, 0)

for _, field := range fieldTypes {
if _, ok := field.Type.(cadence.Function); !ok {
if _, ok := field.Type.(cadence.FunctionType); !ok {
nonFunctionFieldTypes = append(nonFunctionFieldTypes, field)
}
}
Expand Down Expand Up @@ -654,7 +654,6 @@ func prepareType(typ cadence.Type) jsonValue {
case cadence.AnyType,
cadence.AnyStructType,
cadence.AnyResourceType,
cadence.Variable,
cadence.MetaType,
cadence.VoidType,
cadence.NeverType,
Expand Down Expand Up @@ -775,7 +774,7 @@ func prepareType(typ cadence.Type) jsonValue {
Fields: prepareFields(typ.Fields),
Initializers: prepareInitializers(typ.Initializers),
}
case cadence.Function:
case cadence.FunctionType:
return jsonFunctionType{
Kind: "Function",
TypeID: typ.ID(),
Expand Down
2 changes: 1 addition & 1 deletion encoding/json/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,7 @@ func TestEncodeType(t *testing.T) {
testEncodeAndDecode(
t,
cadence.TypeValue{
StaticType: cadence.Function{
StaticType: cadence.FunctionType{
Parameters: []cadence.Parameter{
{Label: "qux", Identifier: "baz", Type: cadence.StringType{}},
},
Expand Down
2 changes: 1 addition & 1 deletion runtime/convertTypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func exportFunctionType(t *sema.FunctionType, results map[sema.TypeID]cadence.Ty

convertedReturnType := ExportType(t.ReturnTypeAnnotation.Type, results)

return cadence.Function{
return cadence.FunctionType{
Parameters: convertedParameters,
ReturnType: convertedReturnType,
}.WithID(string(t.ID()))
Expand Down
43 changes: 9 additions & 34 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,6 @@ func (t OptionalType) ID() string {
return fmt.Sprintf("%s?", t.Type.ID())
}

// Variable

type Variable struct {
Type Type
}

func (Variable) isType() {}

// TODO:
func (Variable) ID() string {
panic("not implemented")
}

// MetaType

type MetaType struct{}
Expand Down Expand Up @@ -441,8 +428,8 @@ func (t VariableSizedArrayType) ID() string {
return fmt.Sprintf("[%s]", t.ElementType.ID())
}

func (v VariableSizedArrayType) Element() Type {
return v.ElementType
func (t VariableSizedArrayType) Element() Type {
return t.ElementType
}

// ConstantSizedArrayType
Expand All @@ -458,8 +445,8 @@ func (t ConstantSizedArrayType) ID() string {
return fmt.Sprintf("[%s;%d]", t.ElementType.ID(), t.Size)
}

func (v ConstantSizedArrayType) Element() Type {
return v.ElementType
func (t ConstantSizedArrayType) Element() Type {
return t.ElementType
}

// DictionaryType
Expand Down Expand Up @@ -777,35 +764,23 @@ func (t *ContractInterfaceType) InterfaceInitializers() [][]Parameter {

// Function

type Function struct {
type FunctionType struct {
typeID string
Parameters []Parameter
ReturnType Type
}

func (t Function) isType() {}
func (FunctionType) isType() {}

func (t Function) ID() string {
func (t FunctionType) ID() string {
return t.typeID
}

func (t Function) WithID(id string) Function {
func (t FunctionType) WithID(id string) FunctionType {
t.typeID = id
return t
}

// ResourcePointer

type ResourcePointer struct {
TypeName string
}

func (ResourcePointer) isType() {}

func (t ResourcePointer) ID() string {
return t.TypeName
}

// ReferenceType

type ReferenceType struct {
Expand Down Expand Up @@ -926,7 +901,7 @@ type EnumType struct {
Initializers [][]Parameter
}

func (t *EnumType) isType() {}
func (*EnumType) isType() {}

func (t *EnumType) ID() string {
if t.Location == nil {
Expand Down