bugfix in smalltalk2java lookup with nil arguments development
authorMarcel Hlopko <marcel.hlopko@fit.cvut.cz>
Sun, 16 Dec 2012 11:53:36 +0100
branchdevelopment
changeset 1886 746919e0fc34
parent 1883 b36e52129040
child 1887 6d3d6ed2d80c
bugfix in smalltalk2java lookup with nil arguments Nil parameter values will now match any formal object argument type, e.g. when two candidate methods show up, one taking primitive type, other one taking object type, and actual parameter class is UndefinedObject, only the other method matches.
JavaLookup.st
JavaLookupTests.st
JavaLookupTestsResource.st
extensions.st
--- a/JavaLookup.st	Sat Dec 15 23:25:19 2012 +0100
+++ b/JavaLookup.st	Sun Dec 16 11:53:36 2012 +0100
@@ -718,16 +718,19 @@
 
 type: actual matches: formal 
     "Return true, if actual (parameter) type matches given formal (parameter) type"
-
-    formal isJavaPrimitiveType ifTrue: [ 
-        actual == SmallInteger ifTrue:[
-            ^formal == Integer or:[actual == formal].
+    
+    formal isJavaPrimitiveType ifTrue: [
+        actual == SmallInteger ifTrue: [
+            ^ formal == Integer or: [ actual == formal ].
         ].
-        formal == Boolean ifTrue:[
-            ^actual == True or:[actual == False or:[actual == Boolean]].
+        formal == Boolean ifTrue: [
+            ^ actual == True or: [ actual == False or: [ actual == Boolean ] ].
         ].
-        ^ actual == formal. 
+        ^ actual == formal.
     ].
+     "nil matches any formal type (to follow undocumented
+     feature of JVM (also seen in CHECKCAST instruction :))" 
+     actual == UndefinedObject ifTrue: [ ^ true ].
     actual isJavaPrimitiveType ifTrue: [
         ^ formal isJavaWrapperClass and: [ formal == actual javaWrapperClass ]
     ].
@@ -739,6 +742,7 @@
     "Created: / 03-01-2012 / 22:36:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 03-04-2012 / 13:59:28 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
     "Modified: / 29-10-2012 / 07:28:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 16-12-2012 / 11:44:17 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
 ! !
 
 !JavaLookup::Smalltalk2Java methodsFor:'utilities (old)'!
--- a/JavaLookupTests.st	Sat Dec 15 23:25:19 2012 +0100
+++ b/JavaLookupTests.st	Sun Dec 16 11:53:36 2012 +0100
@@ -242,6 +242,14 @@
     "Created: / 05-09-2011 / 20:18:30 / Jan Kurs <kursjan@fit.cvut.cz>"
 !
 
+testPassingNilAsParameter
+    "nil should match any formal argument object type (so should not match primitives)"
+    
+    self assert: (self javaTestClass new overloadedMethod: nil) = 3.
+
+    "Created: / 16-12-2012 / 11:35:14 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
+!
+
 testSayHello
     self assert: (self javaTestClass new sayHello = 'hello').
 
@@ -377,6 +385,11 @@
 
 !JavaLookupTests class methodsFor:'documentation'!
 
+version_HG
+
+    ^ '$Changeset: <not expanded> $'
+!
+
 version_SVN
-    ^ '$Id$'
+    ^ '§Id§'
 ! !
--- a/JavaLookupTestsResource.st	Sat Dec 15 23:25:19 2012 +0100
+++ b/JavaLookupTestsResource.st	Sun Dec 16 11:53:36 2012 +0100
@@ -173,8 +173,13 @@
 
 !JavaLookupTestsResource class methodsFor:'documentation'!
 
+version_HG
+
+    ^ '$Changeset: <not expanded> $'
+!
+
 version_SVN
-    ^ '$Id$'
+    ^ '§Id§'
 ! !
 
 JavaLookupTestsResource initialize!
--- a/extensions.st	Sat Dec 15 23:25:19 2012 +0100
+++ b/extensions.st	Sun Dec 16 11:53:36 2012 +0100
@@ -2031,4 +2031,4 @@
 extensionsVersion_HG
 
     ^ '$Changeset: <not expanded> $'
-! !
+! !
\ No newline at end of file