Skip to content

Commit

Permalink
Merge pull request #176 from juanbono/fix_initialize_in_tests_objects…
Browse files Browse the repository at this point in the history
…_classes

make shouldUseOverrideKeyword ignore initialize method
  • Loading branch information
PalumboN authored Dec 14, 2023
2 parents 5797415 + e4ca89c commit ec1bc4b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export const WOLLOK_EXTRA_STACK_TRACE_HEADER = 'Derived from TypeScript stack'

export const WOLLOK_BASE_PACKAGE = 'wollok.'

export const INITIALIZE_METHOD_NAME = 'initialize'

export const PREFIX_OPERATORS: Record<Name, Name> = {
'!': 'negate',
'-': 'invert',
Expand Down Expand Up @@ -59,4 +61,4 @@ export const KEYWORDS = {
FIXTURE: 'fixture',
PROGRAM: 'program',
PACKAGE: 'package',
} as const
} as const

Check warning on line 64 in src/constants.ts

View workflow job for this annotation

GitHub Actions / build

Newline not allowed at end of file
6 changes: 3 additions & 3 deletions src/interpreter/runtimeModel.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { LIST_MODULE, SET_MODULE, WOLLOK_BASE_PACKAGE, WOLLOK_EXTRA_STACK_TRACE_HEADER } from '../constants'
import { v4 as uuid } from 'uuid'
import { INITIALIZE_METHOD_NAME, LIST_MODULE, SET_MODULE, WOLLOK_BASE_PACKAGE, WOLLOK_EXTRA_STACK_TRACE_HEADER } from '../constants'
import { getPotentiallyUninitializedLazy } from '../decorators'
import { get, is, last, List, match, raise, when } from '../extensions'
import { Assignment, Body, Catch, Describe, Environment, Entity, Expression, Id, If, Literal, LiteralValue, Method, Module, Name, New, Node, Package, Program, Reference, Return, Self, Send, Singleton, Super, Test, Throw, Try, Variable, Class } from '../model'
import { Assignment, Body, Catch, Class, Describe, Entity, Environment, Expression, Id, If, Literal, LiteralValue, Method, Module, Name, New, Node, Package, Program, Reference, Return, Self, Send, Singleton, Super, Test, Throw, Try, Variable } from '../model'
import { Interpreter } from './interpreter'

const { isArray } = Array
Expand Down Expand Up @@ -681,7 +681,7 @@ export class Evaluation {
instance.set(field.name, initialValue)
}

yield * this.send('initialize', instance)
yield * this.send(INITIALIZE_METHOD_NAME, instance)

if(!instance.module.name || instance.module.is(Describe))
for (const field of instance.module.allFields)
Expand Down
12 changes: 7 additions & 5 deletions src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
// - Level could be different for the same Expectation on different nodes
// - Problem could know how to convert to string, receiving the interpolation function (so it can be translated). This could let us avoid having parameters.
// - Good default for simple problems, but with a config object for more complex, so we know what is each parameter
import { WOLLOK_BASE_PACKAGE } from './constants'
import { count, TypeDefinition, duplicates, is, isEmpty, last, List, match, notEmpty, when } from './extensions'
import { INITIALIZE_METHOD_NAME, WOLLOK_BASE_PACKAGE } from './constants'
import { count, duplicates, is, isEmpty, last, List, match, notEmpty, TypeDefinition, when } from './extensions'
// - Unified problem type
import { Assignment, Body, Catch, Class, Code, Describe, Entity, Expression, Field, If, Import,
import {

Check warning on line 24 in src/validator.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected line break after this opening brace
Assignment, Body, Catch, Class, Code, Describe, Entity, Expression, Field, If, Import,
Level, Literal, Method, Mixin, Module, NamedArgument, New, Node, Package, Parameter, ParameterizedType, Problem,
Program, Reference, Return, Self, Send, Sentence, Singleton, SourceIndex, SourceMap, Super, Test, Throw, Try, Variable } from './model'
Program, Reference, Return, Self, Send, Sentence, Singleton, SourceIndex, SourceMap, Super, Test, Throw, Try, Variable

Check warning on line 27 in src/validator.ts

View workflow job for this annotation

GitHub Actions / build

Missing trailing comma
} from './model'

Check warning on line 28 in src/validator.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected line break before this closing brace

const { entries } = Object

Expand Down Expand Up @@ -184,7 +186,7 @@ export const shouldOnlyInheritFromMixin = error<Mixin>(node => node.supertypes.e
}))

export const shouldUseOverrideKeyword = warning<Method>(node =>
node.isOverride || !superclassMethod(node)
node.isOverride || !superclassMethod(node) || node.name == INITIALIZE_METHOD_NAME
)

export const possiblyReturningBlock = warning<Method>(node => {
Expand Down

0 comments on commit ec1bc4b

Please sign in to comment.