Skip to content

Commit

Permalink
Fixed issue with self inside nested descriptor callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
somebee committed Jan 30, 2024
1 parent b5caeb3 commit 33678ce
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/imba/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class Something

* Make `@thenable` work for static methods

* Fixed issue with `self` inside nested descriptor callbacks

## 2.0.0-alpha.235

* Call MyMixin.mixes(class) for every class that mixes in MyMixin (if mixes function is defined).
Expand Down
9 changes: 7 additions & 2 deletions packages/imba/src/compiler/nodes.imba1
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,10 @@ export class Stack
def current
@nodes[@nodes:length - 1]

def indexOf test
let res = up(test)
res ? @nodes.indexOf(res) : -1

def up test
test ||= do |v| !(v isa VarOrAccess)

Expand Down Expand Up @@ -4397,8 +4401,9 @@ export class Func < Code
def visit stack, o
# any function inside descriptors should compile as strong scopes
if stack.@descriptor and !stack.tsc
@scope = MethodScope.new(self) # (o and o:scope) || typ.new(self)
@scope.params = @params # = ParamList.new([])
unless stack.indexOf(Func) > stack.indexOf(Descriptor)
@scope = MethodScope.new(self) # (o and o:scope) || typ.new(self)
@scope.params = @params # = ParamList.new([])

scope.visit

Expand Down
18 changes: 18 additions & 0 deletions packages/imba/test/apps/issues/self-in-descriptor.imba
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class @desc
def $get target,key,name
target[key] or callback..call(target)
def $set value,target,key,name
target[key] = value

class Item
number = 2
vals @desc do
[1,2,3].map do
$1 * number




test "works" do
let item = new Item
eq item.vals,[2,4,6]

0 comments on commit 33678ce

Please sign in to comment.