Skip to content

Commit

Permalink
Fix parsing and tests for abstract functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorpy committed Mar 25, 2024
1 parent 3c85b22 commit 58b7d22
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/grammar/__snapshots__/grammar.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,11 @@ Line 6, col 14:
`;
exports[`grammar should fail case-23 1`] = `
"<unknown>:7:1: Abstract function doesn't have abstract modifier
Line 7, col 1:
"<unknown>:7:31: Empty parameter list should not have a dangling comma.
Line 7, col 31:
6 |
> 7 | fun testFuncAbstract(,);
^~~~~~~~~~~~~~~~~~~~~~~~
> 7 | abstract fun testFuncAbstract(,);
^
8 |
"
`;
Expand Down
12 changes: 10 additions & 2 deletions src/grammar/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,11 @@ semantics.addOperation<ASTNode>('resolve_declaration', {
ref: createRef(this)
})
},
Function_abstractVoid(arg0, _arg1, arg2, _arg3, arg4, _arg5, _arg6, _arg7) {
Function_abstractVoid(arg0, _arg1, arg2, _arg3, arg4, arg5, _arg6, _arg7) {
if (arg4.source.contents === '' && arg5.sourceString === ',') {
throwError('Empty parameter list should not have a dangling comma.', createRef(arg5));
}

const attributes = arg0.children.map((v) => v.resolve_attributes()) as ASTFunctionAttribute[];
checkVariableName(arg2.sourceString, createRef(arg2));
checkFunctionAttributes(true, attributes, createRef(this));
Expand All @@ -335,7 +339,11 @@ semantics.addOperation<ASTNode>('resolve_declaration', {
ref: createRef(this)
})
},
Function_abstractType(arg0, _arg1, arg2, _arg3, arg4, _arg5, _arg6, _arg7, arg8, _arg9) {
Function_abstractType(arg0, _arg1, arg2, _arg3, arg4, arg5, _arg6, _arg7, arg8, _arg9) {
if (arg4.source.contents === '' && arg5.sourceString === ',') {
throwError('Empty parameter list should not have a dangling comma.', createRef(arg5));
}

const attributes = arg0.children.map((v) => v.resolve_attributes()) as ASTFunctionAttribute[];
checkVariableName(arg2.sourceString, createRef(arg2));
checkFunctionAttributes(true, attributes, createRef(this));
Expand Down
4 changes: 2 additions & 2 deletions src/grammar/test-failed/case-23.tact
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ native testNativeFunc(,);
@name(native_name_2)
native testNativeFuncWithType(,): Int;

fun testFuncAbstract(,);
abstract fun testFuncAbstract(,);

fun testFuncAbstractWithType(,): Int;
abstract fun testFuncAbstractWithType(,): Int;

0 comments on commit 58b7d22

Please sign in to comment.