Closed markwpearce closed 3 years ago
The transpiled brs is as follows:
You can see that super0_new()
gets overwritten in __StackOverflowTest_ClassC_Namespace_builder
function __StackOverflowTest_ClassA_Namespace_builder()
instance = {}
instance.new = function(name)
m.name = ""
m.name = name
end function
instance.output = function()
for each item in m.Items()
print item.key ; item.value
end for
end function
return instance
end function
function StackOverflowTest_ClassA_Namespace(name)
instance = __StackOverflowTest_ClassA_Namespace_builder()
instance.new(name)
return instance
end function
function __StackOverflowTest_ClassB_Namespace_builder()
instance = __StackOverflowTest_ClassA_Namespace_builder()
instance.super0_new = instance.new
instance.new = function(name, age = 10)
m.super0_new(name)
m.age = 0
' This line will stack overflow
m.age = age
end function
return instance
end function
function StackOverflowTest_ClassB_Namespace(name, age = 10)
instance = __StackOverflowTest_ClassB_Namespace_builder()
instance.new(name, age)
return instance
end function
function __StackOverflowTest_ClassC_Namespace_builder()
instance = __StackOverflowTest_ClassB_Namespace_builder()
instance.super0_new = instance.new
instance.new = function(name, age = 10, color = "")
m.super0_new(name)
m.color = ""
m.color = color
end function
return instance
end function
function StackOverflowTest_ClassC_Namespace(name, age = 10, color = "")
instance = __StackOverflowTest_ClassC_Namespace_builder()
instance.new(name, age, color)
return instance
end function
function __ClassA_NoNamespace_builder()
instance = {}
instance.new = function(name)
m.name = ""
m.name = name
end function
instance.output = function()
for each item in m.Items()
print item.key ; item.value
end for
end function
return instance
end function
function ClassA_NoNamespace(name)
instance = __ClassA_NoNamespace_builder()
instance.new(name)
return instance
end function
function __ClassB_NoNamespace_builder()
instance = __ClassA_NoNamespace_builder()
instance.super0_new = instance.new
instance.new = function(name, age = 10)
m.super0_new(name)
m.age = 0
m.age = age
end function
return instance
end function
function ClassB_NoNamespace(name, age = 10)
instance = __ClassB_NoNamespace_builder()
instance.new(name, age)
return instance
end function
function __ClassC_NoNamespace_builder()
instance = __ClassB_NoNamespace_builder()
instance.super1_new = instance.new
instance.new = function(name, age = 10, color = "")
m.super1_new(name)
m.color = ""
m.color = color
end function
return instance
end function
function ClassC_NoNamespace(name, age = 10, color = "")
instance = __ClassC_NoNamespace_builder()
instance.new(name, age, color)
return instance
end function
Nice catch! So, if you see in the non-namespaced classes, each descendent constructor increments the number next to super. So So in ClassC's constructor, it will end up with this:
instance.super0 = ClassA_NoNamespace.new
instance.super1 = ClassB_NoNamespace.new
instance.new = ClassC_NoNamespace.new
However, for the namespaced class C, we get this:
instance.super0 = StackOverflowTest_ClassA_Namespace.new
instance.super0 = StackOverflowTest_ClassB_Namespace.new
instance.new = StackOverflowTest_ClassC_Namespace.new
I'll dig into this and see what I can find.
Hi, I'm not sure if this is the same issue but I think I'm seeing a regression in 0.65.x:
' source/main.bs
sub Main(args as dynamic)
a = new Tests.Children.ClassMyCustomBenchTest()
print a
sleep(5000)
end sub
' =========
' APP
' =========
namespace App
class ClassCore
sub new()
print "ClassCore.new()"
end sub
end class
end namespace
' =========
' TESTS
' =========
namespace Tests
class ClassTest extends App.ClassCore
end class
class ClassBenchTest extends ClassTest
end class
end namespace
' ==========
' CUSTOM
' ==========
namespace Tests.Children
class ClassMyCustomBenchTest extends Tests.ClassBenchTest
end class
end namespace
EDIT: fixed with #990
The following code causes a stack overflow.
For some reason, the
super()
call inStackOverflowTest.ClassB_Namespace
calls itself - but only when a class that extends that class is constructed.However, there is no issue with "grandchild" classes if they aren't in a namespace.
Tested with brighterscript@0.24.1
Here's some minimalist code that reproduces the issue:
main.bs:
StackOverflowTest.bs: