Skip to content

Commit

Permalink
Merge pull request #310 from uqbar-project/fix-#304-super-inside-closure
Browse files Browse the repository at this point in the history
Fix #304 Super inside closure
  • Loading branch information
PalumboN authored Nov 19, 2024
2 parents baa848d + 1eefd59 commit 25de9db
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BOOLEAN_MODULE, CLOSURE_EVALUATE_METHOD, CLOSURE_TO_STRING_METHOD, INITIALIZE_METHOD, KEYWORDS, NUMBER_MODULE, OBJECT_MODULE, STRING_MODULE, VOID_WKO, WOLLOK_BASE_PACKAGE } from './constants'
import { BOOLEAN_MODULE, CLOSURE_EVALUATE_METHOD, CLOSURE_MODULE, CLOSURE_TO_STRING_METHOD, INITIALIZE_METHOD, KEYWORDS, NUMBER_MODULE, OBJECT_MODULE, STRING_MODULE, VOID_WKO, WOLLOK_BASE_PACKAGE } from './constants'
import { getPotentiallyUninitializedLazy } from './decorators'
import { count, is, isEmpty, last, List, match, notEmpty, otherwise, valueAsListOrEmpty, when, excludeNullish } from './extensions'
import { RuntimeObject, RuntimeValue } from './interpreter/runtimeModel'
Expand Down Expand Up @@ -217,7 +217,7 @@ export const usesField = (node: Node, field: Field): boolean =>
match(node)(
when(Singleton)(node => {
if (!node.isClosure()) return false
const applyMethod = node.methods.find(method => method.name === CLOSURE_EVALUATE_METHOD)
const applyMethod = node.methods.find(isApplyMethodForClosures)
return !!applyMethod && usesField(applyMethod, field)
}),
when(Variable)(node => usesField(node.value, field)),
Expand Down Expand Up @@ -441,8 +441,14 @@ export const getNodeDefinition = (environment: Environment) => (node: Node): Nod
}
}

export const isApplyMethodForClosures = (method: Method): boolean =>
method.name === CLOSURE_EVALUATE_METHOD && method.parent.fullyQualifiedName.startsWith(`${CLOSURE_MODULE}#`) // TODO: Maybe re-define isClosure() ?

export const superMethodDefinition = (superNode: Super, methodModule: Module): Method | undefined => {
const currentMethod = superNode.ancestors.find(is(Method))!
function isValidMethod(node: Node): node is Method {
return node.is(Method) && !isApplyMethodForClosures(node)
}
const currentMethod = superNode.ancestors.find(isValidMethod)!
return methodModule.lookupMethod(currentMethod.name, superNode.args.length, { lookupStartFQN: currentMethod.parent.fullyQualifiedName })
}

Expand Down
1 change: 0 additions & 1 deletion test/interpreter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,6 @@ describe('Wollok Interpreter', () => {
expect(errored).to.be.false
})


})

describe('DirectedInterpreter', () => {
Expand Down

0 comments on commit 25de9db

Please sign in to comment.