Skip to content

Commit

Permalink
Better handling of incomplete function signatures (#1103)
Browse files Browse the repository at this point in the history
Enhancements:
- Improved error reporting and parser recovery for incomplete function signatures (see #1086)
  • Loading branch information
degory authored Mar 4, 2024
1 parent a622a22 commit 1ecfbbf
Show file tree
Hide file tree
Showing 192 changed files with 1,866 additions and 131 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
]
},
"ghul.compiler": {
"version": "0.8.9",
"version": "0.8.10",
"commands": [
"ghul-compiler"
]
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>0.8.10-alpha.10</Version>
<Version>0.8.11-alpha.14</Version>
<NoWarn>$(NoWarn);NU1507</NoWarn>
</PropertyGroup>

Expand Down
15 changes: 11 additions & 4 deletions integration-tests/edit-failed.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
#!/bin/bash
for f in `find integration-tests -name failed`; do
DIR=`dirname $f`

if [ ! -f $DIR/disabled ] ; then
code `dirname $f` ; read -n 1 -s
FAILED=""

for f in $(find integration-tests -name failed); do
DIR=$(dirname "$f")

if [ ! -f "$DIR/disabled" ]; then
FAILED="$FAILED $DIR"
fi
done

if [ -n "$FAILED" ]; then
code $FAILED
fi
1 change: 0 additions & 1 deletion integration-tests/parse/incomplete-function-2/err.expected
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
test.ghul: 4,18..4,26: error: explicit argument type required
test.ghul: 5,5..5,7: error: syntax error: expected ) but found si
2 changes: 1 addition & 1 deletion integration-tests/parse/incomplete-function-2/test.ghul
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ namespace Test.ParseUnary is
class Test is
function(argument
si
si
si
1 change: 0 additions & 1 deletion integration-tests/parse/incomplete-function-3/err.expected
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
test.ghul: 6,5..6,7: error: in type expression: expected ( or identifier but found si
test.ghul: 6,5..6,7: error: syntax error: expected ) but found si
2 changes: 1 addition & 1 deletion integration-tests/parse/incomplete-function-3/test.ghul
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Test.ParseUnary is
namespace Test.IncompleteMethodSignature is
use Collections;

class Test is
Expand Down
1 change: 0 additions & 1 deletion integration-tests/parse/incomplete-function-7/err.expected
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
test.ghul: 3,28..3,30: error: in type expression: expected ( or identifier but found in
test.ghul: 4,5..4,7: error: syntax error: expected ) but found si
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Run test",
"command": "dotnet ghul-test \"${workspaceFolder}\"",
"type": "shell",
"group": {
"kind": "test",
"isDefault": true
}
},
{
"label": "Capture test expectation",
"command": "../../../tasks/capture.sh \"${workspaceFolder}\"",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test.ghul: 11,16..11,17: error: syntax error: incomplete formal arguments
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compiler": "dotnet ../../../publish/ghul.dll",
"source": [
"."
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--type-check
Empty file.
33 changes: 33 additions & 0 deletions integration-tests/parse/incomplete-function-signature-1/test.ghul
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use IO.Std.write_line;

test_first(a: int) is
write_line("test_first");
si

test_before(b: string) is
write_line("test_before");
si

test_incomplete(

test_after(c: int) is
write_line("test_after");
si

test_last() is
write_line("test_last");
si

entry() is
test_first(1);
test_before("a");

// test_incomplete() should be defined,
// even though its argument list is incomplete
// and it should have zero formal arguments:
test_incomplete();

test_after(2);
test_last();
si

Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Run test",
"command": "dotnet ghul-test \"${workspaceFolder}\"",
"type": "shell",
"group": {
"kind": "test",
"isDefault": true
}
},
{
"label": "Capture test expectation",
"command": "../../../tasks/capture.sh \"${workspaceFolder}\"",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test.ghul: 6,15..6,16: error: syntax error: expected , but found identifier b
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compiler": "dotnet ../../../publish/ghul.dll",
"source": [
"."
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--type-check
Empty file.
44 changes: 44 additions & 0 deletions integration-tests/parse/incomplete-function-signature-10/test.ghul
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use IO.Std.write_line;

test_first(a: int) is
write_line("test_first");
si

test_before(b: string) is
write_line("test_before");
si

test_incomplete(a: int, b: int) -> Collections.LIST[ // FIXME: error cascade

test_after(c: int) is
write_line("test_after");

si

test_last() is
write_line("test_last");
si

entry() is
test_first(1);
test_before("a");

// test_incomplete() should be definedd
// it should have two arguments, both
// of which are of type int
test_incomplete(123, 456);

test_incomplete("abc", "abc"); // expect error

// ideally test_incomplete() would have a return type
// of error (compatible with any type) but we
// can't represent that as a type expression, only
// as an actual type, so the error we get here is
// not that helpful

let a: int = test_incomplete(123, 456); // expect error

test_after(2);
test_last();
si

Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Run test",
"command": "dotnet ghul-test \"${workspaceFolder}\"",
"type": "shell",
"group": {
"kind": "test",
"isDefault": true
}
},
{
"label": "Capture test expectation",
"command": "../../../tasks/capture.sh \"${workspaceFolder}\"",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test.ghul: 13,24..13,25: error: syntax error: incomplete formal arguments
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compiler": "dotnet ../../../publish/ghul.dll",
"source": [
"."
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--type-check
Empty file.
36 changes: 36 additions & 0 deletions integration-tests/parse/incomplete-function-signature-11/test.ghul
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace Test is
use IO.Std.write_line;

class TEST is
test_first(a: int) is
write_line("test_first");
si

test_before(b: string) is
write_line("test_before");
si

test_incomplete(

test_after(c: int) is
write_line("test_after");
si

test_last() is
write_line("test_last");
si

init() is
test_first(1);
test_before("a");

// test_incomplete() should be defined,
// even though its argument list is incomplete
// and it should have zero formal arguments:
test_incomplete();

test_after(2);
test_last();
si
si
si
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Run test",
"command": "dotnet ghul-test \"${workspaceFolder}\"",
"type": "shell",
"group": {
"kind": "test",
"isDefault": true
}
},
{
"label": "Capture test expectation",
"command": "../../../tasks/capture.sh \"${workspaceFolder}\"",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test.ghul: 13,25..13,26: error: syntax error: incomplete formal arguments
test.ghul: 35,29..35,30: error: no overload found for test_incomplete()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compiler": "dotnet ../../../publish/ghul.dll",
"source": [
"."
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--type-check
Empty file.
41 changes: 41 additions & 0 deletions integration-tests/parse/incomplete-function-signature-12/test.ghul
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
namespace TestIncompleteMethodSignature12 is
use IO.Std.write_line;

class TEST is
test_first(a: int) is
write_line("test_first");
si

test_before(b: string) is
write_line("test_before");
si

test_incomplete(a:

test_after(c: int) is
write_line("test_after");

si

test_last() is
write_line("test_last");
si

entry() is
test_first(1);
test_before("a");

// test_incomplete() should be defined,
// even though its argument list is incomplete
// and it should have one formal argument
// of error type (accepts any type of argument)
test_incomplete(123);
test_incomplete("abc");

test_incomplete(); // expect error

test_after(2);
test_last();
si
si
si
Empty file.
Loading

0 comments on commit 1ecfbbf

Please sign in to comment.