As my colleague Mathias pointed out today, “ActionScript is War”. On the one side are we, innocent developers, on the other hand Adobe’s crappy piece of a compiler.

Introduction

In the program we’re currently working on, we moved some classes to another namespace and generated a bunch of components that were referencing each other. We had

  • VariableList: A container for variables with a DataGroup in it.
  • VariableEditor: A ItemRenderer for the DataGroup in VariableList
  • ValueEditor: A tiny component that was loaded into the VariableEditor depending on the variables type.
  • Numeric-, DropDown-, Generic-, String-, BooleanEditor: Type-specific descendants of the ValueEditor.

The VariableEditor had an internal property globalOrSegment, that was accessed by method in the concrete ValueEditors though a reference to the VariableEditor, namely variableEditor.globalOrSegment. So far so boring. Now the fun part was, that sometimes, this reference caused an error in the compiler:

Access of possibly undefined property globalOrSegmentVar through a reference with static type .components.variables:VariableEditor.

WTF! This message came seemingly random, sometimes the code would compile, sometimes it wouldn’t. Now, performing a clean before each debug run would eliminate the randomess. Code compiled this way would either always fail or always pass. But this just turned our attention to something even stranger: Several certain commits to the VariableEditor that was (or seemed) completely harmless (another if statement in one of the methods) would turn the compiler from friend to foe. There was no pattern.

Good luck I had a vague memory of something like that happening somewhere before (not even remembering where, it wasn’t even ActionScript). That time, the compiler was trippin up because it didn’t resolve the namespaces and classes correctly. Now you’d guess that was a rather simple problem and compilers these days were smart enough to solve this problem?

After all we did TopSort in our first semester.

Well, guess again.

Now you only need a way to give the compiler a nudge in the right direction. A hint which classes to resolve first. I solved this by putting a simple list of references into the body of the VariableList class:

public class VariableList extends SkinnableContainer implements IDisposable
{   
    VariableEditor;
    BooleanEditor;
    DropDownEditor;
    GenericEditor;
    NumericEditor;
    StringEditor;
    TextEditor;
    ...
}

Well that worked. Took me 45 minutes. Could have taken me forever if I didn’t have had that gut feeling. And googling “possibly undefined property” does not exactly yield helpful results, just a bunch of noobs not understanding static typing.

Well, here’s the solution.