#1114 Invalid field for tableswitch: compiler::FField

ivan Tue 8 Jun 2010


Today I found a bug related to using FPodNamespace during compilation: I have two pods with structure like this

  enum class Foo { A, B }
  Foo field 
    case Foo.A: doSomething //compiler err from subj

As it turned out, the problem is in compiler::Expr.asTableSwitchCase, as it does not know how to get ordinal from FField. I created a simple 3 lines patch which works, however not sure if it is absolutely correct (i.e. patch assumes that fields are written to FCode in the same order as in source file and are not shuffled after reading):

diff -r a16481a4d6bf src/compiler/fan/ast/Expr.fan
--- a/src/compiler/fan/ast/Expr.fan	Tue Jun 08 01:03:06 2010 -0400
+++ b/src/compiler/fan/ast/Expr.fan	Tue Jun 08 21:01:46 2010 +0700
@@ -1038,6 +1038,9 @@
           fieldDef := field as FieldDef
           enumDef := fieldDef.parentDef.enumDef(field.name)
           if (enumDef != null) return enumDef.ordinal
+        case FField#:
+          ffield := field as FField
+          return ffield.fparent.ffields.index(ffield)
           throw CompilerErr("Invalid field for tableswitch: " + field.typeof, loc)

brian Tue 8 Jun 2010

Promoted to ticket #1114 and assigned to brian

brian Thu 9 Sep 2010

Ticket resolved in 1.0.55

Using the field order is clever, but probably not the most robust design. What I did instead was add a new fcode attribute EnumOrdinal for enum fields so that pulling that ordinal value out of the fcode is easy.


Login or Signup to reply.