Skip to content

Commit 69317ee

Browse files
author
dlsmith
committed
DynamicJava: Class/interface members of interfaces are always static. Improved error messages for allocations (missing enclosing object, bad anonymous supertype, etc.)
git-svn-id: file:///tmp/test-svn/trunk@5055 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent 6ac6b30 commit 69317ee

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

dynamicjava/src/edu/rice/cs/dynamicjava/interpreter/ExpressionChecker.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -871,12 +871,18 @@ private void addRuntimeCheck(Node node, Type expectedType, Type declaredActualTy
871871
*/
872872
@Override public Type visit(SimpleAllocation node) {
873873
Type t = checkTypeName(node.getCreationType());
874-
if (!ts.isConcrete(t)) { throw new ExecutionError("allocation.type", node); }
874+
if (!ts.isConcrete(t)) {
875+
setErrorStrings(node, ts.userRepresentation(t));
876+
throw new ExecutionError("allocation.type", node);
877+
}
875878

876879
Option<Type> dynamicOuter = ts.dynamicallyEnclosingType(t);
877880
if (dynamicOuter.isSome()) {
878881
DJClass enclosingThis = enclosingThis(dynamicOuter.unwrap());
879-
if (enclosingThis == null) { throw new ExecutionError("allocation.type", node); }
882+
if (enclosingThis == null) {
883+
setErrorStrings(node, ts.userRepresentation(t), ts.userRepresentation(dynamicOuter.unwrap()));
884+
throw new ExecutionError("inner.allocation", node);
885+
}
880886
else { setEnclosingThis(node, enclosingThis); }
881887
}
882888

@@ -911,13 +917,17 @@ private void addRuntimeCheck(Node node, Type expectedType, Type declaredActualTy
911917
@Override public Type visit(AnonymousAllocation node) {
912918
Type t = checkTypeName(node.getCreationType());
913919
if (!ts.isExtendable(t) && !ts.isImplementable(t)) {
914-
throw new ExecutionError("allocation.type", node);
920+
setErrorStrings(node, ts.userRepresentation(t));
921+
throw new ExecutionError("invalid.supertype", node);
915922
}
916923

917924
Option<Type> dynamicOuter = ts.dynamicallyEnclosingType(t);
918925
if (dynamicOuter.isSome()) {
919926
DJClass enclosingThis = enclosingThis(dynamicOuter.unwrap());
920-
if (enclosingThis == null) { throw new ExecutionError("allocation.type", node); }
927+
if (enclosingThis == null) {
928+
setErrorStrings(node, ts.userRepresentation(t), ts.userRepresentation(dynamicOuter.unwrap()));
929+
throw new ExecutionError("inner.allocation", node);
930+
}
921931
else { setEnclosingThis(node, enclosingThis); }
922932
}
923933

@@ -993,6 +1003,7 @@ private DJClass enclosingThis(Type expected) {
9931003
throw new ExecutionError("static.inner.allocation", node);
9941004
}
9951005
if (!ts.isConcrete(t)) {
1006+
setErrorStrings(node, ts.userRepresentation(t));
9961007
throw new ExecutionError("allocation.type", node);
9971008
}
9981009

@@ -1049,7 +1060,8 @@ private DJClass enclosingThis(Type expected) {
10491060
throw new ExecutionError("static.inner.allocation", node);
10501061
}
10511062
if (!ts.isExtendable(t)) {
1052-
throw new ExecutionError("allocation.type", node);
1063+
setErrorStrings(node, ts.userRepresentation(t));
1064+
throw new ExecutionError("invalid.supertype", node);
10531065
}
10541066
setSuperType(node, t);
10551067

dynamicjava/src/edu/rice/cs/dynamicjava/symbol/TreeClass.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,10 @@ public String declaredName() {
191191

192192
public boolean isInterface() { return _ast instanceof InterfaceDeclaration; }
193193

194-
public boolean isStatic() { return _ast instanceof EnumDeclaration || _mods.isStatic(); }
194+
public boolean isStatic() {
195+
if (_declaring == null) { return false; }
196+
else { return _declaring.isInterface() || _ast instanceof EnumDeclaration || _mods.isStatic(); }
197+
}
195198
public boolean isAbstract() { return _mods.isAbstract(); }
196199
public boolean isFinal() { return _mods.isFinal(); }
197200
public Access accessibility() { return extractAccessibility(_mods); }

dynamicjava/src/koala/dynamicjava/interpreter/resources/messages.properties

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,9 @@ abstract.method.body = The abstract method '%0' must not have a body
159159
# Used by ClassInfoCompiler
160160
addition.type = Bad type in addition
161161

162-
# Used by TypeChecker
163-
allocation.type = Bad type in allocation
162+
allocation.type = Cannot construct a %0: a concrete class is required
163+
inner.allocation = Cannot construct a %0: an enclosing object of type %1 is required
164+
static.inner.allocation = Class '%0' is a static member of type %1
164165

165166

166167
# Used by TypeChecker
@@ -215,7 +216,11 @@ duplicate.switch.case = 'switch' contains multiple blocks for the same case
215216

216217
illegal.private.access = Illegal access of private member '%0'
217218
illegal.package.access = Illegal access of package-private member '%0'
218-
illegal.protected.access = Illegal access of protected member '%0'
219+
illegal.protected.access = Illegal access of protected member '%0'
220+
221+
invalid.superclass = Type %0 is not a valid superclass
222+
invalid.superinterface = Type %0 is not a valid superinterface
223+
invalid.supertype = Type %0 is not a valid supertype
219224

220225
# Used by ClassInfoCompiler, TypeChecker
221226
increment.type = Bad type in increment expression
@@ -308,8 +313,6 @@ selector.type = Bad 'switch' selector type: %0
308313
# Used by ClassInfoCompiler, TypeChecker
309314
shift.expression.type = Bad type in shift expression
310315

311-
static.inner.allocation = Class '%0' is a static member of type %1
312-
313316
# Used by TypeChecker
314317
super.undefined = 'super' is undefined in this context
315318

0 commit comments

Comments
 (0)