Skip to content

Commit

Permalink
Fix a definite assignment bug for multi-condition IfStatements
Browse files Browse the repository at this point in the history
  • Loading branch information
Gene Gleyzer committed Jun 21, 2022
1 parent d6ac22b commit 5b366af
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions javatools/src/main/java/org/xvm/compiler/ast/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -1993,6 +1993,7 @@ private void copyAssignments(Context ctxSrc, Context ctxDst)
mapDst.put(sName, entry.getValue());
}
}
ctxDst.setReachable(ctxSrc.isReachable());
}

private void discardBranch(boolean fWhenTrue)
Expand Down
24 changes: 16 additions & 8 deletions manualTests/src/main/x/TestSimple.x
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,25 @@ module TestSimple
{
@Inject Console console;

void run()
void run( )
{
Map<Int, String> map = new HashMap();
Boolean flag = True;

Type type = &map.actualType;
console.println(type);
Map<Int, String> map;
if (String name := name(), flag)
{
TODO
}
else
{
map = new HashMap();
}

Type type1 = (immutable).add(type);
console.println(type1);
console.println(map); // use to fail to compile: Variable "map" is not definitely assigned
}

Type type2 = type.add((immutable));
console.println(type2);
conditional String name()
{
return False;
}
}

0 comments on commit 5b366af

Please sign in to comment.