Skip to content

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

Open
@davidhbrown-uri

Description

@davidhbrown-uri

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions