Skip to content

Commit

Permalink
Avoid unnecessary default-func delegator generation for interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
SupunS committed Feb 3, 2025
1 parent 0ee77c8 commit a550727
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 44 deletions.
11 changes: 0 additions & 11 deletions bbq/compiler/desugar.go
Original file line number Diff line number Diff line change
Expand Up @@ -1231,17 +1231,6 @@ func (d *Desugar) VisitInterfaceDeclaration(declaration *ast.InterfaceDeclaratio
d.modifiedDeclarations = append(d.modifiedDeclarations, desugaredMember)
}

// Add inherited default functions.
existingFunctions := declaration.Members.FunctionsByIdentifier()
inheritedDefaultFuncs := d.inheritedDefaultFunctions(
interfaceType,
existingFunctions,
declaration.StartPos,
declaration.Range,
)

d.modifiedDeclarations = append(d.modifiedDeclarations, inheritedDefaultFuncs...)

// TODO: Optimize: If none of the existing members got updated or,
// if there are no inherited members, then return the same declaration as-is.

Expand Down
33 changes: 0 additions & 33 deletions interpreter/function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,36 +323,3 @@ func TestInterpretFunctionSubtyping(t *testing.T) {
result,
)
}

func TestInterpretDefaultFunctionWithConditions(t *testing.T) {

t.Parallel()

inter, getLogs, err := parseCheckAndInterpretWithLogs(t, `
struct interface Foo {
fun test(_ a: Int) {
log("Calling to Foo.test")
}
}
struct interface Bar: Foo {
fun test(_ a: Int) {
pre {
a > 10: "a must be greater than 10"
}
}
}
struct Test: Bar {}
fun main() {
Test().test(12)
}`,
)

_, err = inter.Invoke("main")
require.NoError(t, err)

logs := getLogs()
require.Empty(t, logs)
}

0 comments on commit a550727

Please sign in to comment.