From 595736b8c64d6f025643e3b811684f94ba9fdebf Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Thu, 30 May 2013 14:39:58 +0200 Subject: [PATCH] Fixed: When selector is only a ':' in a send message statement the new compiler crashed. The program below crashed on the last line with a 'null is not an object' error message. Also added a test case. @implementation MyObject { - (int):(int)a { return a; } @end var a = [[MyObject alloc] init]; var b = [a:3]; --- Objective-J/ObjJAcornCompiler.js | 3 ++- .../Preprocessor/OutputTests/Messages/colon-selector.j | 2 ++ .../Preprocessor/OutputTests/Messages/colon-selector.js | 2 ++ Tests/Objective-J/Preprocessor/OutputTests/OutputTest.j | 1 + 4 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 Tests/Objective-J/Preprocessor/OutputTests/Messages/colon-selector.j create mode 100644 Tests/Objective-J/Preprocessor/OutputTests/Messages/colon-selector.js diff --git a/Objective-J/ObjJAcornCompiler.js b/Objective-J/ObjJAcornCompiler.js index d8851579b..9bdad14a3 100644 --- a/Objective-J/ObjJAcornCompiler.js +++ b/Objective-J/ObjJAcornCompiler.js @@ -1577,7 +1577,8 @@ MessageSendExpression: function(node, st, c) { var selectors = node.selectors, arguments = node.arguments, - selector = selectors[0].name; // There is always at least one selector + firstSelector = selectors[0], + selector = firstSelector ? firstSelector.name : ""; // There is always at least one selector // Put together the selector. Maybe this should be done in the parser... for (var i = 0; i < arguments.length; i++) diff --git a/Tests/Objective-J/Preprocessor/OutputTests/Messages/colon-selector.j b/Tests/Objective-J/Preprocessor/OutputTests/Messages/colon-selector.j new file mode 100644 index 000000000..f995cbbbd --- /dev/null +++ b/Tests/Objective-J/Preprocessor/OutputTests/Messages/colon-selector.j @@ -0,0 +1,2 @@ + +[object:argument]; diff --git a/Tests/Objective-J/Preprocessor/OutputTests/Messages/colon-selector.js b/Tests/Objective-J/Preprocessor/OutputTests/Messages/colon-selector.js new file mode 100644 index 000000000..aff484c53 --- /dev/null +++ b/Tests/Objective-J/Preprocessor/OutputTests/Messages/colon-selector.js @@ -0,0 +1,2 @@ + +objj_msgSend(object, ":", argument); diff --git a/Tests/Objective-J/Preprocessor/OutputTests/OutputTest.j b/Tests/Objective-J/Preprocessor/OutputTests/OutputTest.j index d457565e7..3083447d2 100644 --- a/Tests/Objective-J/Preprocessor/OutputTests/OutputTest.j +++ b/Tests/Objective-J/Preprocessor/OutputTests/OutputTest.j @@ -12,6 +12,7 @@ var FILENAMES = [ "Messages/multiple-parameters", "Messages/ternary-operator-argument", "Messages/keyword-in-selector", + "Messages/colon-selector", "Misc/parenthesis-return", "Misc/preprocess-if-directives",