Permalink
Browse files

Fix by Leonardo Borges for JRUBY-2349: Bug in constant lookup on non …

…Module or Class
  • Loading branch information...
headius committed Jun 13, 2009
1 parent 6c63118 commit e85018a30cc1d1f8ff2abcf8fa029c6d32397e82
@@ -1 +0,0 @@
-fails(JRUBY-2349):A class definition raises TypeError if the constant qualifying the class is nil
@@ -83,6 +83,8 @@ public Node getLeftNode() {
/** Get parent module/class that this module represents */
@Override
public RubyModule getEnclosingModule(Ruby runtime, ThreadContext context, IRubyObject self, Block aBlock) {
+ if (leftNode != null && leftNode instanceof NilNode)
+ throw context.getRuntime().newTypeError("no outer class/module");
return RuntimeHelpers.prepareClassNamespace(context, leftNode.interpret(runtime, context, self, aBlock));
}
}
@@ -34,36 +34,53 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+
import org.jruby.RubyInstanceConfig;
+import org.jruby.RubyMatchData;
import org.jruby.ast.AliasNode;
import org.jruby.ast.AndNode;
+import org.jruby.ast.ArgsCatNode;
import org.jruby.ast.ArgsNode;
+import org.jruby.ast.ArgsPushNode;
import org.jruby.ast.ArrayNode;
import org.jruby.ast.AttrAssignNode;
import org.jruby.ast.BackRefNode;
import org.jruby.ast.BeginNode;
import org.jruby.ast.BignumNode;
import org.jruby.ast.BinaryOperatorNode;
import org.jruby.ast.BlockNode;
+import org.jruby.ast.BlockPassNode;
import org.jruby.ast.BreakNode;
import org.jruby.ast.CallNode;
+import org.jruby.ast.CaseNode;
+import org.jruby.ast.ClassNode;
import org.jruby.ast.ClassVarAsgnNode;
+import org.jruby.ast.ClassVarDeclNode;
import org.jruby.ast.ClassVarNode;
+import org.jruby.ast.Colon2ConstNode;
+import org.jruby.ast.Colon2MethodNode;
import org.jruby.ast.Colon2Node;
import org.jruby.ast.Colon3Node;
import org.jruby.ast.ConstDeclNode;
import org.jruby.ast.ConstNode;
import org.jruby.ast.DAsgnNode;
+import org.jruby.ast.DRegexpNode;
import org.jruby.ast.DStrNode;
+import org.jruby.ast.DSymbolNode;
import org.jruby.ast.DVarNode;
+import org.jruby.ast.DXStrNode;
import org.jruby.ast.DefinedNode;
import org.jruby.ast.DefnNode;
+import org.jruby.ast.DefsNode;
import org.jruby.ast.DotNode;
import org.jruby.ast.EnsureNode;
import org.jruby.ast.EvStrNode;
import org.jruby.ast.FCallNode;
+import org.jruby.ast.FileNode;
import org.jruby.ast.FixnumNode;
+import org.jruby.ast.FlipNode;
import org.jruby.ast.FloatNode;
+import org.jruby.ast.ForNode;
import org.jruby.ast.GlobalAsgnNode;
import org.jruby.ast.GlobalVarNode;
import org.jruby.ast.HashNode;
@@ -77,64 +94,49 @@
import org.jruby.ast.Match2Node;
import org.jruby.ast.Match3Node;
import org.jruby.ast.MatchNode;
+import org.jruby.ast.ModuleNode;
+import org.jruby.ast.MultipleAsgnNode;
import org.jruby.ast.NewlineNode;
import org.jruby.ast.NextNode;
+import org.jruby.ast.NilNode;
import org.jruby.ast.Node;
import org.jruby.ast.NodeType;
import org.jruby.ast.NotNode;
import org.jruby.ast.NthRefNode;
-import org.jruby.ast.OpAsgnOrNode;
import org.jruby.ast.OpAsgnNode;
+import org.jruby.ast.OpAsgnOrNode;
+import org.jruby.ast.OpElementAsgnNode;
import org.jruby.ast.OrNode;
+import org.jruby.ast.PostExeNode;
+import org.jruby.ast.PreExeNode;
import org.jruby.ast.RegexpNode;
import org.jruby.ast.RescueBodyNode;
import org.jruby.ast.RescueNode;
import org.jruby.ast.ReturnNode;
import org.jruby.ast.RootNode;
+import org.jruby.ast.SClassNode;
import org.jruby.ast.SValueNode;
import org.jruby.ast.SplatNode;
+import org.jruby.ast.StarNode;
import org.jruby.ast.StrNode;
import org.jruby.ast.SuperNode;
import org.jruby.ast.SymbolNode;
-import org.jruby.ast.VCallNode;
-import org.jruby.ast.WhileNode;
-import org.jruby.ast.YieldNode;
-import org.jruby.runtime.Arity;
-import org.jruby.runtime.CallType;
-import org.jruby.exceptions.JumpException;
-import org.jruby.RubyMatchData;
-import org.jruby.ast.ArgsCatNode;
-import org.jruby.ast.ArgsPushNode;
-import org.jruby.ast.BlockPassNode;
-import org.jruby.ast.CaseNode;
-import org.jruby.ast.ClassNode;
-import org.jruby.ast.ClassVarDeclNode;
-import org.jruby.ast.Colon2ConstNode;
-import org.jruby.ast.Colon2MethodNode;
-import org.jruby.ast.DRegexpNode;
-import org.jruby.ast.DSymbolNode;
-import org.jruby.ast.DXStrNode;
-import org.jruby.ast.DefsNode;
-import org.jruby.ast.FileNode;
-import org.jruby.ast.FlipNode;
-import org.jruby.ast.ForNode;
-import org.jruby.ast.ModuleNode;
-import org.jruby.ast.MultipleAsgnNode;
-import org.jruby.ast.OpElementAsgnNode;
-import org.jruby.ast.PostExeNode;
-import org.jruby.ast.PreExeNode;
-import org.jruby.ast.SClassNode;
-import org.jruby.ast.StarNode;
import org.jruby.ast.ToAryNode;
import org.jruby.ast.UndefNode;
import org.jruby.ast.UntilNode;
import org.jruby.ast.VAliasNode;
+import org.jruby.ast.VCallNode;
import org.jruby.ast.WhenNode;
import org.jruby.ast.WhenOneArgNode;
+import org.jruby.ast.WhileNode;
import org.jruby.ast.XStrNode;
+import org.jruby.ast.YieldNode;
import org.jruby.ast.ZSuperNode;
+import org.jruby.exceptions.JumpException;
import org.jruby.parser.StaticScope;
+import org.jruby.runtime.Arity;
import org.jruby.runtime.BlockBody;
+import org.jruby.runtime.CallType;
/**
*
@@ -1003,7 +1005,11 @@ public void call(BodyCompiler context) {
if (cpathNode instanceof Colon2Node) {
Node leftNode = ((Colon2Node) cpathNode).getLeftNode();
if (leftNode != null) {
- compile(leftNode, context, true);
+ if (leftNode instanceof NilNode) {
+ context.raiseTypeError("No outer class");
+ } else {
+ compile(leftNode, context, true);
+ }
} else {
context.loadNil();
}
@@ -587,4 +587,6 @@ public void compileSequencedConditional(
List<ArgumentsCallback> conditionals,
List<CompilerCallback> bodies,
CompilerCallback fallback);
+
+ public void raiseTypeError(String string);
}
@@ -1945,6 +1945,13 @@ public void aliasGlobal(String newName, String oldName) {
method.invokevirtual(p(GlobalVariables.class), "alias", sig(Void.TYPE, params(String.class, String.class)));
loadNil();
}
+
+ public void raiseTypeError(String msg) {
+ loadRuntime();
+ method.ldc(msg);
+ invokeRuby("newTypeError", sig(RaiseException.class, params(String.class)));
+ method.athrow();
+ }
public void undefMethod(String name) {
loadThreadContext();
@@ -577,7 +577,7 @@ public static RubyClass prepareSuperClass(Ruby runtime, IRubyObject rubyClass) {
}
public static RubyModule prepareClassNamespace(ThreadContext context, IRubyObject rubyModule) {
- if (rubyModule == null || rubyModule.isNil()) { // the isNil check should go away since class nil::Foo;end is not supposed be correct
+ if (rubyModule == null || rubyModule.isNil()) {
rubyModule = context.getCurrentScope().getStaticScope().getModule();
if (rubyModule == null) {

0 comments on commit e85018a

Please sign in to comment.