[Swift-commit] r5548 - trunk/src/org/griphyn/vdl/engine

hategan at ci.uchicago.edu hategan at ci.uchicago.edu
Sun Feb 5 04:33:37 CST 2012


Author: hategan
Date: 2012-02-05 04:33:36 -0600 (Sun, 05 Feb 2012)
New Revision: 5548

Modified:
   trunk/src/org/griphyn/vdl/engine/Karajan.java
Log:
check if type is actually a structure on field access and generate a proper error instead of a NPE

Modified: trunk/src/org/griphyn/vdl/engine/Karajan.java
===================================================================
--- trunk/src/org/griphyn/vdl/engine/Karajan.java	2012-02-04 23:45:26 UTC (rev 5547)
+++ trunk/src/org/griphyn/vdl/engine/Karajan.java	2012-02-05 10:33:36 UTC (rev 5548)
@@ -1325,23 +1325,27 @@
 				parentType = baseType;
 			}
 
-			String actualType = null;
 			// TODO this should be a map lookup of some kind?
 
 			Type t = typesMap.get(parentType);
-
+			
+			if (t == null) {
+			    // this happens when trying to access a field of a built-in type
+			    // which cannot currently be a structure
+			    throw new CompilationException("Type " + parentType + " is not a structure");
+			}
+			
 			TypeStructure ts = t.getTypestructure();
-			int j = 0;
-			for (j = 0; j < ts.sizeOfMemberArray(); j++) {
+			
+			String actualType = null;
+			for (int j = 0; j < ts.sizeOfMemberArray(); j++) {
 				if (ts.getMemberArray(j).getMembername().equals(sm.getMemberName())) 	{
 					actualType = ts.getMemberArray(j).getMembertype();
 					break;
 				}
-			if (j == ts.sizeOfMemberArray())
-				throw new CompilationException("No member " + sm.getMemberName() + " in structure " + parentType);
 			}
 			if (actualType == null) {
-				throw new CompilationException("Type " + parentType + " is not defined.");
+                throw new CompilationException("No member " + sm.getMemberName() + " in type " + parentType);
 			}
 			StringTemplate newst;
 			if(arrayMode) {




More information about the Swift-commit mailing list