Skip to content

Commit

Permalink
Cleanup unused code. Fix linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
SupunS committed Jan 24, 2025
1 parent 1212aa2 commit b0570bb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 54 deletions.
40 changes: 0 additions & 40 deletions ast/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/turbolent/prettier"

"github.com/onflow/cadence/common"
"github.com/onflow/cadence/errors"
)

type Block struct {
Expand Down Expand Up @@ -354,45 +353,6 @@ func (c *EmitCondition) Walk(walkChild func(Element)) {
(*EmitStatement)(c).Walk(walkChild)
}

// DesugaredCondition is only used in desugar phase.
type DesugaredCondition struct {
Condition Statement
}

var _ Condition = &DesugaredCondition{}

func NewDesugaredCondition(condition Statement) *DesugaredCondition {
return &DesugaredCondition{
Condition: condition,
}
}

func (c DesugaredCondition) StartPosition() Position {
return c.Condition.StartPosition()
}

func (c DesugaredCondition) EndPosition(memoryGauge common.MemoryGauge) Position {
return c.Condition.EndPosition(memoryGauge)
}

func (c DesugaredCondition) ElementType() ElementType {
return ElementTypeUnknown
}

func (c DesugaredCondition) Walk(walkChild func(Element)) {
walkChild(c.Condition)
}

func (c DesugaredCondition) isCondition() {}

func (c DesugaredCondition) CodeElement() Element {
return c.Condition
}

func (c DesugaredCondition) Doc() prettier.Doc {
panic(errors.NewUnreachableError())
}

// Conditions

type Conditions struct {
Expand Down
29 changes: 16 additions & 13 deletions bbq/compiler/desugar.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package compiler

import (
"fmt"

"github.com/onflow/cadence/ast"
"github.com/onflow/cadence/bbq/commons"
"github.com/onflow/cadence/common"
Expand Down Expand Up @@ -105,15 +106,13 @@ func (d *Desugar) VisitFunctionDeclaration(declaration *ast.FunctionDeclaration)
funcBlock := declaration.FunctionBlock
funcName := declaration.Identifier.Identifier

var preConditions, postConditions []ast.Statement

preConditions = d.desugarConditions(
preConditions := d.desugarConditions(
funcName,
ast.ConditionKindPre,
funcBlock,
declaration.ParameterList,
)
postConditions = d.desugarConditions(
postConditions := d.desugarConditions(
funcName,
ast.ConditionKindPost,
funcBlock,
Expand Down Expand Up @@ -288,10 +287,9 @@ func (d *Desugar) desugarConditions(
desugaredConditions = append(desugaredConditions, invocation)
}
}
} else {
if funcBlock != nil {
conditions = funcBlock.PostConditions
}
} else if funcBlock != nil {
// Post conditions
conditions = funcBlock.PostConditions
}

// Desugar self-defined pre/post conditions
Expand Down Expand Up @@ -345,20 +343,25 @@ func (d *Desugar) desugarConditions(

// Otherwise, i.e: if this is an interface function with only pre/post conditions,
// (thus not a default function), then generate a separate function for the conditions.
d.generateConditionsFunction(enclosingFuncName, kind, pos, conditions, desugaredConditions, list)
d.generateConditionsFunction(
enclosingFuncName,
kind,
conditions,
desugaredConditions,
list,
)

return nil
}

func (d *Desugar) generateConditionsFunction(
enclosingFuncName string,
kind ast.ConditionKind,
pos ast.Position,
conditions *ast.Conditions,
desugaredConditions []ast.Statement,
list *ast.ParameterList,
) {
pos = conditions.StartPos
pos := conditions.StartPos

desugaredConditions = append(
desugaredConditions,
Expand Down Expand Up @@ -650,7 +653,7 @@ func (d *Desugar) inheritedFunctionsWithConditions(compositeType *sema.Composite
interfaceDecl := elaboration.InterfaceTypeDeclaration(interfaceType)
functions := interfaceDecl.Members.FunctionsByIdentifier()

for name, functionDecl := range functions {
for name, functionDecl := range functions { // nolint:maprange
if !functionDecl.FunctionBlock.HasConditions() {
continue
}
Expand All @@ -674,7 +677,7 @@ func (d *Desugar) inheritedDefaultFunctions(compositeType *sema.CompositeType, d

inheritedMembers := make([]ast.Declaration, 0)

for memberName, resolver := range allMembers {
for memberName, resolver := range allMembers { // nolint:maprange
if directMembers.Contains(memberName) {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion bbq/vm/test/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ func parseCheckAndCompileCodeWithOptions(
return program
}

func parseAndCheck(
func parseAndCheck( // nolint:unused
t testing.TB,
code string,
location common.Location,
Expand Down

0 comments on commit b0570bb

Please sign in to comment.