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

Empty "do" statement list causes student and redundant pattern detector confusion #326

Open
davidhbrown-uri opened this issue Oct 11, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@davidhbrown-uri
Copy link

The following code is a simplification of a conceptual error I've seen in student code when learning multiple dispatch:

function foo with bar do
    with baz do 0 
end

Awkwardly, asteroid reports "error: list index out of range" on the second line of the function. This is not particularly informative as there are no lists in the asteroid code.

Turning on Python exceptions with -e shows that this actually came from:

.../asteroid/walk.py, line 1994, in check_redundancy
    first_line_h = LINE_LIST[0]

Turning off the redundant pattern detector with -r lets the function work with the empty statement list (in Asteroid 2.0.2), returning none. Here's a more useful variation on the theme:

load system io.
function foo with 0 do
    with 1 do "not none"
end
io@println(tostring(foo(0))).
io@println(tostring(foo(1))).

(With the -r flag, prints none and not none.)

So, it does seem to be a legal program, just one which confuses the pattern redundancy detector, and that error confuses students.

I haven't looked enough at the codebase to know how difficult it would be to issue a warning if a program's AST includes an empty statement list, but that could be helpful.

@lutzhamel lutzhamel added the bug Something isn't working label Oct 12, 2024
@lutzhamel
Copy link
Collaborator

lutzhamel commented Oct 12, 2024

We need to fix Asteroid's grammar to disallow with clauses with no statements.

As a workaround, simply put the 'noop' statement -- a single period.

load system io.
function foo with 0 do .  <<<
    with 1 do "not none"
end
io@println(tostring(foo(0))).
io@println(tostring(foo(1))).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants