diff --git a/src/grammar/__snapshots__/grammar.spec.ts.snap b/src/grammar/__snapshots__/grammar.spec.ts.snap index 75df231c8..3aaad493a 100644 --- a/src/grammar/__snapshots__/grammar.spec.ts.snap +++ b/src/grammar/__snapshots__/grammar.spec.ts.snap @@ -221,12 +221,21 @@ Line 6, col 14: `; exports[`grammar should fail case-23 1`] = ` -":7:31: Empty parameter list should not have a dangling comma. -Line 7, col 31: - 6 | -> 7 | abstract fun testFuncAbstract(,); +":2:23: Empty parameter list should not have a dangling comma. +Line 2, col 23: + 1 | @name(native_name_1) +> 2 | native testNativeFunc(,); + ^ + 3 | +" +`; + +exports[`grammar should fail case-24 1`] = ` +":1:31: Empty parameter list should not have a dangling comma. +Line 1, col 31: +> 1 | abstract fun testFuncAbstract(,); ^ - 8 | + 2 | " `; diff --git a/src/grammar/grammar.ts b/src/grammar/grammar.ts index 7672932ef..9b34c3b90 100644 --- a/src/grammar/grammar.ts +++ b/src/grammar/grammar.ts @@ -345,8 +345,6 @@ semantics.addOperation('resolve_declaration', { } const attributes = arg0.children.map((v) => v.resolve_attributes()) as ASTFunctionAttribute[]; - checkVariableName(arg2.sourceString, createRef(arg2)); - checkFunctionAttributes(true, attributes, createRef(this)); return createNode({ kind: 'def_function', origin: ctx!.origin, @@ -358,7 +356,11 @@ semantics.addOperation('resolve_declaration', { ref: createRef(this) }) }, - NativeFunction_withType(_arg0, _arg1, arg2, _arg3, arg4, arg5, arg6, _arg7, arg8, _arg9, _arg10, _arg11, arg12, _arg13) { + NativeFunction_withType(_arg0, _arg1, arg2, _arg3, arg4, arg5, arg6, _arg7, arg8, arg9, _arg10, _arg11, arg12, _arg13) { + if (arg8.source.contents === '' && arg9.sourceString === ',') { + throwError('Empty parameter list should not have a dangling comma.', createRef(arg9)); + } + checkVariableName(arg5.sourceString, createRef(arg5)); return createNode({ kind: 'def_native_function', @@ -371,7 +373,11 @@ semantics.addOperation('resolve_declaration', { ref: createRef(this) }) }, - NativeFunction_withVoid(_arg0, _arg1, arg2, _arg3, arg4, arg5, arg6, _arg7, arg8, _arg9, _arg10, _arg11) { + NativeFunction_withVoid(_arg0, _arg1, arg2, _arg3, arg4, arg5, arg6, _arg7, arg8, arg9, _arg10, _arg11) { + if (arg8.source.contents === '' && arg9.sourceString === ',') { + throwError('Empty parameter list should not have a dangling comma.', createRef(arg9)); + } + checkVariableName(arg5.sourceString, createRef(arg5)); return createNode({ kind: 'def_native_function', diff --git a/src/grammar/test-failed/case-23.tact b/src/grammar/test-failed/case-23.tact index 6037f335f..9ee5bcfc0 100644 --- a/src/grammar/test-failed/case-23.tact +++ b/src/grammar/test-failed/case-23.tact @@ -3,7 +3,3 @@ native testNativeFunc(,); @name(native_name_2) native testNativeFuncWithType(,): Int; - -abstract fun testFuncAbstract(,); - -abstract fun testFuncAbstractWithType(,): Int; \ No newline at end of file diff --git a/src/grammar/test-failed/case-24.tact b/src/grammar/test-failed/case-24.tact new file mode 100644 index 000000000..54a56e33a --- /dev/null +++ b/src/grammar/test-failed/case-24.tact @@ -0,0 +1,3 @@ +abstract fun testFuncAbstract(,); + +abstract fun testFuncAbstractWithType(,): Int; \ No newline at end of file