handling imported vars fix

This commit is contained in:
Jindra Petřík
2021-02-25 20:51:27 +01:00
parent 5ea2cc42a1
commit 0a0e04bab8
6 changed files with 41 additions and 10 deletions

View File

@@ -2709,6 +2709,8 @@ public class AVM2SourceGenerator implements SourceGenerator {
typeItem = item;
} else if (item instanceof ApplyTypeAVM2Item) {
typeItem = ((ApplyTypeAVM2Item) item).object;
} else if (item instanceof ImportedSlotConstItem) {
typeItem = ((ImportedSlotConstItem) item).type;
} else {
throw new CompilationException("Invalid type:" + item + " (" + item.getClass().getName() + ")", 0/*??*/);
}

View File

@@ -73,6 +73,9 @@ public class CallAVM2Item extends AVM2Item {
if (callable instanceof UnresolvedAVM2Item) {
callable = ((UnresolvedAVM2Item) callable).resolved;
}
if (callable instanceof ImportedSlotConstItem) {
callable = ((ImportedSlotConstItem) callable).type;
}
if (callable instanceof NameAVM2Item) {
NameAVM2Item n = (NameAVM2Item) callable;
/*List<ABC> allAbcs = new ArrayList<>();

View File

@@ -30,11 +30,11 @@ import java.util.List;
*
* @author JPEXS
*/
public class TypeAssignableItem extends AssignableAVM2Item {
public class ImportedSlotConstItem extends AssignableAVM2Item {
private final TypeItem type;
public TypeItem type;
public TypeAssignableItem(TypeItem type) {
public ImportedSlotConstItem(TypeItem type) {
this.type = type;
}
@@ -50,12 +50,12 @@ public class TypeAssignableItem extends AssignableAVM2Item {
@Override
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
return type.returnType();
}
@Override
public AssignableAVM2Item copy() {
return new TypeAssignableItem(type);
return new ImportedSlotConstItem(type);
}
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn) throws CompilationException {
@@ -116,4 +116,14 @@ public class TypeAssignableItem extends AssignableAVM2Item {
return ret;
}
@Override
public String toString() {
return type.toString();
}
@Override
public String toString(LocalData localData) throws InterruptedException {
return super.toString(localData); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@@ -330,11 +330,12 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item {
}
if (name.size() == 1) {
resolved = new TypeAssignableItem(ret);
//TODO: check whether it is really an assignable and not a Class
if (assignedValue != null) {
((TypeAssignableItem) resolved).assignedValue = assignedValue;
//throw new CompilationException("Cannot assign type", line);
AbcIndexing.TraitIndex ti = abc.findScriptProperty(imp);
if (ti != null && (ti.trait instanceof TraitSlotConst)) {
resolved = new ImportedSlotConstItem(ret);
if (assignedValue != null) {
((ImportedSlotConstItem) resolved).assignedValue = assignedValue;
}
}
}

View File

@@ -54,6 +54,7 @@ package
TestIfElse;
TestIfInIf;
TestIgnoreAndOr;
TestImportedVar;
TestInc2;
TestIncDec;
TestInlineFunctions;

View File

@@ -0,0 +1,14 @@
package tests
{
import tests_classes.myvar;
public class TestImportedVar
{
public function run():void
{
trace(myvar);
//myvar++;
myvar = 5;
}
}
}