Skip to content

Java backend: variable redeclaration in same scope #336

@ldayton

Description

@ldayton

Summary

The Java backend emits duplicate String ch declarations in the same method scope, causing "variable ch is already defined" compile errors. Java doesn't allow redeclaring a variable in the same scope, unlike Python where reassignment to the same name is always valid.

Reproduction

Transpiled Java:

void _parse_backtick_substitution() {
    String ch = ...;
    // ... later in same method ...
    String ch = ...;  // ERROR: variable ch is already defined
}

Impact

2 compile errors in _parse_backtick_substitution().

Fix

The Java backend should track declared variables per scope and emit plain assignment (ch = ...) instead of re-declaration (String ch = ...) when the variable already exists.

Discovered via ldayton/Parable#413.

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendbugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions