Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.13 SmalltalkImage>>at:ifAbsent: has a bug #1046

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/Kernel-Infrastructure.js
Original file line number Diff line number Diff line change
Expand Up @@ -2939,19 +2939,21 @@ selector: "at:ifAbsent:",
protocol: 'accessing',
fn: function (aKey,aBlock){
var self=this;
var foundOrNil;
return smalltalk.withContext(function($ctx1) {
var $2,$1;
$2=self._includesKey_(aKey);
foundOrNil=_st(self._globals())._at_(aKey);
$2=_st(foundOrNil)._notNil();
if(smalltalk.assert($2)){
$1=self._at_(aKey);
$1=foundOrNil;
} else {
$1=_st(aBlock)._value();
};
return $1;
}, function($ctx1) {$ctx1.fill(self,"at:ifAbsent:",{aKey:aKey,aBlock:aBlock},globals.SmalltalkImage)})},
}, function($ctx1) {$ctx1.fill(self,"at:ifAbsent:",{aKey:aKey,aBlock:aBlock,foundOrNil:foundOrNil},globals.SmalltalkImage)})},
args: ["aKey", "aBlock"],
source: "at: aKey ifAbsent: aBlock\x0a\x09^ (self includesKey: aKey)\x0a\x09\x09ifTrue: [ self at: aKey ]\x0a\x09\x09ifFalse: [ aBlock value ]",
messageSends: ["ifTrue:ifFalse:", "includesKey:", "at:", "value"],
source: "at: aKey ifAbsent: aBlock\x0a\x0a\x09| foundOrNil |\x0a\x0a\x09foundOrNil := self globals at: aKey.\x0a\x0a\x09^ foundOrNil notNil\x0a\x09\x09ifTrue: [ foundOrNil ]\x0a\x09\x09ifFalse: [ aBlock value ]",
messageSends: ["at:", "globals", "ifTrue:ifFalse:", "notNil", "value"],
referencedClasses: []
}),
globals.SmalltalkImage);
Expand Down
9 changes: 7 additions & 2 deletions src/Kernel-Infrastructure.st
Original file line number Diff line number Diff line change
Expand Up @@ -1124,8 +1124,13 @@ at: aString
!

at: aKey ifAbsent: aBlock
^ (self includesKey: aKey)
ifTrue: [ self at: aKey ]

| foundOrNil |

foundOrNil := self globals at: aKey.

^ foundOrNil notNil
ifTrue: [ foundOrNil ]
ifFalse: [ aBlock value ]
!

Expand Down
34 changes: 34 additions & 0 deletions src/Kernel-Tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3480,6 +3480,40 @@ referencedClasses: ["Dictionary"]
}),
globals.DictionaryTest);

smalltalk.addMethod(
smalltalk.method({
selector: "testSmalltalkGlobals",
protocol: 'tests',
fn: function (){
var self=this;
function $Smalltalk(){return globals.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
function $Dictionary(){return globals.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
return smalltalk.withContext(function($ctx1) {
var $1,$3,$2;
$1=_st(_st($Smalltalk())._at_("Dictionary")).__eq_eq($Dictionary());
$ctx1.sendIdx["=="]=1;
self._assert_($1);
$ctx1.sendIdx["assert:"]=1;
$3=_st($Smalltalk())._at_ifAbsent_("Dictionary",(function(){
return smalltalk.withContext(function($ctx2) {
return (6).__plus((5));
$ctx2.sendIdx["+"]=1;
}, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
$ctx1.sendIdx["at:ifAbsent:"]=1;
$2=(11).__eq($3);
self._deny_($2);
self._assert_(_st(_st($Smalltalk())._at_ifAbsent_("Dictionary",(function(){
return smalltalk.withContext(function($ctx2) {
return (6).__plus((5));
}, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}))).__eq_eq($Dictionary()));
return self}, function($ctx1) {$ctx1.fill(self,"testSmalltalkGlobals",{},globals.DictionaryTest)})},
args: [],
source: "testSmalltalkGlobals\x0a\x0a\x09self assert: (Smalltalk at: 'Dictionary') == Dictionary.\x0a\x09self deny: 11 = (Smalltalk at: 'Dictionary' ifAbsent: [ 6 + 5 ]).\x0a\x09\x0a\x09self assert: (Smalltalk at: 'Dictionary' ifAbsent: [ 6 + 5 ]) == Dictionary.",
messageSends: ["assert:", "==", "at:", "deny:", "=", "at:ifAbsent:", "+"],
referencedClasses: ["Smalltalk", "Dictionary"]
}),
globals.DictionaryTest);


smalltalk.addMethod(
smalltalk.method({
Expand Down
8 changes: 8 additions & 0 deletions src/Kernel-Tests.st
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,14 @@ testAccessing

testDynamicDictionaries
self assert: #{'hello' -> 1} asDictionary equals: (Dictionary with: 'hello' -> 1)
!

testSmalltalkGlobals

self assert: (Smalltalk at: 'Dictionary') == Dictionary.
self deny: 11 = (Smalltalk at: 'Dictionary' ifAbsent: [ 6 + 5 ]).

self assert: (Smalltalk at: 'Dictionary' ifAbsent: [ 6 + 5 ]) == Dictionary.
! !

!DictionaryTest class methodsFor: 'fixture'!
Expand Down