Skip to content

Commit c179e9f

Browse files
committed
Bug in assert when we create a Control instance.
1 parent 6f45ba4 commit c179e9f

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

src/Core/Control.moon

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,15 @@ class Control
205205

206206
if p
207207
if p["__class"]
208-
_rootParent = p.__class.__parent
209-
while _rootParent != Control
210-
_rootParent = _rootParent.__parent
208+
if p.__class != Control
209+
_rootParent = p.__class.__parent
210+
while _rootParent != Control
211+
_rootParent = _rootParent.__parent
211212
else
212213
error "parent must a class."
213214

215+
_rootParent = _rootParent or p
216+
214217
assert (p == nil) or (p.__class == Control) or (_rootParent.__class == Control),
215218
"parent must be nil or Control or a subclass of Control."
216219

@@ -240,12 +243,15 @@ class Control
240243
local _rootParent
241244

242245
if child["__class"]
243-
_rootParent = child.__class.__parent
244-
while _rootParent != Control
245-
_rootParent = _rootParent.__parent
246+
if child.__class != Control
247+
_rootParent = child.__class.__parent
248+
while _rootParent != Control
249+
_rootParent = _rootParent.__parent
246250
else
247251
error "parent must a class."
248252

253+
_rootParent = _rootParent or child
254+
249255
assert (child.__class == Control) or (_rootParent.__class == Control),
250256
"child must be Control or a subclass of Control."
251257

@@ -464,12 +470,14 @@ class Control
464470
local _rootParent
465471

466472
if target["__class"]
467-
_rootParent = target.__class.__parent
468-
while _rootParent != Control
469-
_rootParent = _rootParent.__parent
473+
if target.__class != Control
474+
_rootParent = target.__class.__parent
475+
while _rootParent != Control
476+
_rootParent = _rootParent.__parent
470477
else
471478
error "target must a class."
472-
479+
480+
_rootParent = _rootParent or target
473481
assert (target.__class == Control) or (_rootParent.__class == Control),
474482
"target must be a Control or a subclass of Control."
475483

src/Core/Debug.moon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ class Debug extends Singleton
9393
if @focusControl.boxType == "Polygon" then cy = 160
9494
else cy = 148
9595
parent = focusControl\getParent!
96-
if parent == nil then pname = "None"
97-
else pname = parent.__name
96+
if parent == nil then pname = "Control"
97+
else pname = parent.__name or "Control"
9898
Graphics.print "Parent: " .. pname, @x + 10, @y + cy
9999
Graphics.print "Depth: " .. focusControl.depth, @x + 10, @y + cy + 12
100100
Graphics.print "#Children: " .. #focusControl.children, @x + 10, @y + cy + 24

0 commit comments

Comments
 (0)