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

Fix Value.Type() returning Type referencing nil ptr for eight external values #2388

Merged
merged 5 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 0 additions & 7 deletions runtime/format/capability.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,3 @@ func StorageCapability(borrowType string, address string, path string) string {
path,
)
}

func AccountCapability(address string) string {
fxamacker marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Sprintf(
"Capability(address: %s)",
address,
)
}
47 changes: 46 additions & 1 deletion values.go
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,7 @@ func (v Array) String() string {
// Dictionary

type Dictionary struct {
DictionaryType Type
DictionaryType *DictionaryType
Pairs []KeyValuePair
}

Expand All @@ -1453,6 +1453,11 @@ func NewMeteredDictionary(
func (Dictionary) isValue() {}

func (v Dictionary) Type() Type {
if v.DictionaryType == nil {
fxamacker marked this conversation as resolved.
Show resolved Hide resolved
// Return nil Type instead of Type referencing nil *DictionaryType,
// so caller can check if v's type is nil and also prevent nil pointer dereference.
return nil
}
return v.DictionaryType
}

Expand Down Expand Up @@ -1541,6 +1546,11 @@ func NewMeteredStruct(
func (Struct) isValue() {}

func (v Struct) Type() Type {
if v.StructType == nil {
// Return nil Type instead of Type referencing nil *StructType,
// so caller can check if v's type is nil and also prevent nil pointer dereference.
return nil
}
return v.StructType
}

Expand Down Expand Up @@ -1619,6 +1629,11 @@ func NewMeteredResource(
func (Resource) isValue() {}

func (v Resource) Type() Type {
if v.ResourceType == nil {
// Return nil Type instead of Type referencing nil *ResourceType,
// so caller can check if v's type is nil and also prevent nil pointer dereference.
return nil
}
return v.ResourceType
}

Expand Down Expand Up @@ -1676,6 +1691,11 @@ func NewMeteredAttachment(
func (Attachment) isValue() {}

func (v Attachment) Type() Type {
if v.AttachmentType == nil {
// Return nil Type instead of Type referencing nil *AttachmentType,
// so caller can check if v's type is nil and also prevent nil pointer dereference.
return nil
}
return v.AttachmentType
}

Expand Down Expand Up @@ -1733,6 +1753,11 @@ func NewMeteredEvent(
func (Event) isValue() {}

func (v Event) Type() Type {
if v.EventType == nil {
// Return nil Type instead of Type referencing nil *EventType,
// so caller can check if v's type is nil and also prevent nil pointer dereference.
return nil
}
return v.EventType
}

Expand Down Expand Up @@ -1789,6 +1814,11 @@ func NewMeteredContract(
func (Contract) isValue() {}

func (v Contract) Type() Type {
if v.ContractType == nil {
// Return nil Type instead of Type referencing nil *ContractType,
// so caller can check if v's type is nil and also prevent nil pointer dereference.
return nil
}
return v.ContractType
}

Expand Down Expand Up @@ -2012,6 +2042,11 @@ func NewMeteredEnum(
func (Enum) isValue() {}

func (v Enum) Type() Type {
if v.EnumType == nil {
// Return nil Type instead of Type referencing nil *EnumType,
// so caller can check if v's type is nil and also prevent nil pointer dereference.
return nil
}
return v.EnumType
}

Expand Down Expand Up @@ -2059,9 +2094,19 @@ func NewMeteredFunction(gauge common.MemoryGauge, functionType *FunctionType) Fu
func (Function) isValue() {}

func (v Function) Type() Type {
if v.FunctionType == nil {
// Return nil Type instead of Type referencing nil *FunctionType,
// so caller can check if v's type is nil and also prevent nil pointer dereference.
return nil
}
return v.FunctionType
}

func (v Function) WithType(functionType *FunctionType) Function {
v.FunctionType = functionType
return v
}

turbolent marked this conversation as resolved.
Show resolved Hide resolved
func (v Function) MeteredType(common.MemoryGauge) Type {
return v.FunctionType
}
Expand Down
Loading