Browse Source

fix for Set >> #add:

Nicolas Petton 5 years ago
parent
commit
4fd0f219c9

+ 1 - 1
js/Kernel-Collections.deploy.js

@@ -3408,7 +3408,7 @@ return smalltalk.withContext(function($ctx1) {
 
 		var found;
 		for(var i=0; i < self['@elements'].length; i++) {
-			if(anObject == self['@elements'][i]) {
+			if(_st(anObject).__eq_eq(self['@elements'][i])) {
 				found = true;
 				break;
 			}

+ 2 - 2
js/Kernel-Collections.js

@@ -4579,7 +4579,7 @@ return smalltalk.withContext(function($ctx1) {
 
 		var found;
 		for(var i=0; i < self['@elements'].length; i++) {
-			if(anObject == self['@elements'][i]) {
+			if(_st(anObject).__eq_eq(self['@elements'][i])) {
 				found = true;
 				break;
 			}
@@ -4588,7 +4588,7 @@ return smalltalk.withContext(function($ctx1) {
 	;
 return self}, function($ctx1) {$ctx1.fill(self,"add:",{anObject:anObject},smalltalk.Set)})},
 args: ["anObject"],
-source: "add: anObject\x0a\x09<\x0a\x09\x09var found;\x0a\x09\x09for(var i=0; i < self['@elements'].length; i++) {\x0a\x09\x09\x09if(anObject == self['@elements'][i]) {\x0a\x09\x09\x09\x09found = true;\x0a\x09\x09\x09\x09break;\x0a\x09\x09\x09}\x0a\x09\x09}\x0a\x09\x09if(!found) {self['@elements'].push(anObject)}\x0a\x09>",
+source: "add: anObject\x0a\x09<\x0a\x09\x09var found;\x0a\x09\x09for(var i=0; i < self['@elements'].length; i++) {\x0a\x09\x09\x09if(_st(anObject).__eq_eq(self['@elements'][i])) {\x0a\x09\x09\x09\x09found = true;\x0a\x09\x09\x09\x09break;\x0a\x09\x09\x09}\x0a\x09\x09}\x0a\x09\x09if(!found) {self['@elements'].push(anObject)}\x0a\x09>",
 messageSends: [],
 referencedClasses: []
 }),

+ 11 - 0
js/Kernel-Tests.deploy.js

@@ -3338,6 +3338,17 @@ return self}, function($ctx1) {$ctx1.fill(self,"testSize",{},smalltalk.SetTest)}
 messageSends: ["assert:equals:", "size", "new", "withAll:"]}),
 smalltalk.SetTest);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "testUnboxedObjects",
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+self._assert_equals_(_st(_st(["foo"._yourself(),"foo"._yourself()])._asSet())._asArray(),["foo"]);
+return self}, function($ctx1) {$ctx1.fill(self,"testUnboxedObjects",{},smalltalk.SetTest)})},
+messageSends: ["assert:equals:", "asArray", "asSet", "yourself"]}),
+smalltalk.SetTest);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "testUnicity",

+ 16 - 0
js/Kernel-Tests.js

@@ -4204,6 +4204,22 @@ referencedClasses: ["Set"]
 }),
 smalltalk.SetTest);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "testUnboxedObjects",
+category: 'tests',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+self._assert_equals_(_st(_st(["foo"._yourself(),"foo"._yourself()])._asSet())._asArray(),["foo"]);
+return self}, function($ctx1) {$ctx1.fill(self,"testUnboxedObjects",{},smalltalk.SetTest)})},
+args: [],
+source: "testUnboxedObjects\x0a\x09self assert: {'foo' yourself. 'foo' yourself} asSet asArray equals: #('foo')",
+messageSends: ["assert:equals:", "asArray", "asSet", "yourself"],
+referencedClasses: []
+}),
+smalltalk.SetTest);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "testUnicity",

+ 1 - 1
st/Kernel-Collections.st

@@ -1516,7 +1516,7 @@ add: anObject
 	<
 		var found;
 		for(var i=0; i < self['@elements'].length; i++) {
-			if(anObject == self['@elements'][i]) {
+			if(_st(anObject).__eq_eq(self['@elements'][i])) {
 				found = true;
 				break;
 			}

+ 4 - 0
st/Kernel-Tests.st

@@ -1600,6 +1600,10 @@ testSize
 	self assert: (Set withAll: #(1 1 1 1)) size equals: 1
 !
 
+testUnboxedObjects
+	self assert: {'foo' yourself. 'foo' yourself} asSet asArray equals: #('foo')
+!
+
 testUnicity
 	| set |
 	set := Set new.