Skip to content

Commit

Permalink
Merge pull request #2388 from onflow/fxamacker/fix-nil-ptr-to-type
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent authored Mar 22, 2023
2 parents 25f5791 + 7a6b490 commit 6ac267c
Show file tree
Hide file tree
Showing 3 changed files with 281 additions and 202 deletions.
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 {
return fmt.Sprintf(
"Capability(address: %s)",
address,
)
}
42 changes: 41 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 {
// 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,6 +2094,11 @@ 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
}

Expand Down
Loading

0 comments on commit 6ac267c

Please sign in to comment.