From 891923a17d914cab1d143adeef96fc38acbb14ad Mon Sep 17 00:00:00 2001 From: Marcus Denker Date: Tue, 11 Jun 2019 14:24:42 +0200 Subject: [PATCH] do not forget to pop the value when storing in the temp in #emitStore: fixes #3478 --- src/Slot-Examples/ProcessLocalSlot.class.st | 1 + src/Slot-Examples/WeakSlot.class.st | 1 + src/Slot-Tests/ProcessLocalSlotTest.class.st | 23 ++++++++++++++++++++ src/Spec-Core/SpecObservableSlot.class.st | 1 + 4 files changed, 26 insertions(+) diff --git a/src/Slot-Examples/ProcessLocalSlot.class.st b/src/Slot-Examples/ProcessLocalSlot.class.st index 56568431723..1f49c5f0cbd 100644 --- a/src/Slot-Examples/ProcessLocalSlot.class.st +++ b/src/Slot-Examples/ProcessLocalSlot.class.st @@ -37,6 +37,7 @@ ProcessLocalSlot >> emitStore: aMethodBuilder [ "We pop the value from the stack into a temp to push it back in the right order" aMethodBuilder addTemp: temp. aMethodBuilder storeTemp: temp. + aMethodBuilder popTop. "Push the process local variable into the stack, then the value again, then send" aMethodBuilder pushInstVar: index. diff --git a/src/Slot-Examples/WeakSlot.class.st b/src/Slot-Examples/WeakSlot.class.st index 2ae43cf7577..bfe1a985718 100644 --- a/src/Slot-Examples/WeakSlot.class.st +++ b/src/Slot-Examples/WeakSlot.class.st @@ -25,6 +25,7 @@ WeakSlot >> emitStore: aMethodBuilder [ "Pop the value to store into a temp to push it back in the right order" aMethodBuilder addTemp: temp. aMethodBuilder storeTemp: temp. + aMethodBuilder popTop. "Push the weak array into the stack, then the arguments, then send" aMethodBuilder pushInstVar: index. diff --git a/src/Slot-Tests/ProcessLocalSlotTest.class.st b/src/Slot-Tests/ProcessLocalSlotTest.class.st index 0c4be67dc8d..e71f852f94c 100644 --- a/src/Slot-Tests/ProcessLocalSlotTest.class.st +++ b/src/Slot-Tests/ProcessLocalSlotTest.class.st @@ -4,6 +4,29 @@ Class { #category : #'Slot-Tests-Examples' } +{ #category : #tests } +ProcessLocalSlotTest >> testIsPossibleToSetSlotInBlock [ + | slot writerString instance | + slot := #slot1 => ProcessLocalSlot. + aClass := self make: [ :builder | builder slots: {slot} ]. + + writerString := String streamContents: [ :str | + str + nextPutAll: slot name; + nextPutAll: ': anObject'; + cr;tab; + nextPutAll: 'true ifTrue: [ '; + nextPutAll: slot name; + nextPutAll: ':= anObject ]'. + ]. + + aClass compile: writerString. + + instance := aClass new. + instance slot1: #test. + self assert: (instance instVarNamed: #slot1) value equals: #test. +] + { #category : #tests } ProcessLocalSlotTest >> testRead [ | slot | diff --git a/src/Spec-Core/SpecObservableSlot.class.st b/src/Spec-Core/SpecObservableSlot.class.st index 5a6927034f4..98f94f33198 100644 --- a/src/Spec-Core/SpecObservableSlot.class.st +++ b/src/Spec-Core/SpecObservableSlot.class.st @@ -13,6 +13,7 @@ SpecObservableSlot >> emitStore: aMethodBuilder [ "We pop the value from the stack into a temp to push it back in the right order" aMethodBuilder addTemp: temp. aMethodBuilder storeTemp: temp. + aMethodBuilder popTop. "Push the value holder into the stack, then the value again, then send" aMethodBuilder pushInstVar: index.