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

correccion de error en repl cuando se redefinia una variable #319

Merged
merged 5 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion src/interpreter/runtimeModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,13 +488,21 @@ export class Evaluation {
}

protected *execVariable(node: Variable): Execution<void> {
const variableFullName = targetName(node, node.name)

if(this.currentFrame.locals.get(variableFullName)){
throw new Error('Can\'t redefine a variable')
}

const value = yield* this.exec(node.value)

assertNotVoid(value, `Cannot assign to variable '${node.name}': ${getExpressionFor(node.value)} produces no value, cannot assign it to a variable`)

yield node

this.currentFrame.set(targetName(node, node.name), value)
this.currentFrame.set(variableFullName, value)


}

protected *execAssignment(node: Assignment): Execution<void> {
Expand Down
18 changes: 18 additions & 0 deletions test/interpreter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,24 @@ describe('Wollok Interpreter', () => {
)
})

it('Can\'t redefine a variable', () => {
const replEnvironment = buildEnvironment([{
name: REPL, content: `
const variableName = 1
`,
}])
interpreter = new Interpreter(Evaluation.build(replEnvironment, WRENatives))
const { error } = interprete(interpreter, 'var variableName = 2')
assertBasicError(error)
expect(getStackTraceSanitized(error)).to.deep.equal(
[
'wollok.lang.EvaluationError: Error: Can\'t redefine a variable',

]
)
fdodino marked this conversation as resolved.
Show resolved Hide resolved
})


it('should wrap void validation errors for assignment to void value', () => {
const replEnvironment = buildEnvironment([{
name: REPL, content: `
Expand Down
Loading