bmx-ng / bcc

A next-generation bcc parser for BlitzMax
zlib License
33 stars 12 forks source link

First-class functions do not work in NG #626

Open noroads2015 opened 3 years ago

noroads2015 commented 3 years ago

Describe the bug Trying to create an array of function pointers. Works fine in vanilla BlitzMax, but gives errors in NG Expression of Type String cannot be inkoked. To Reproduce


Local f:String(n:Int)[10]

f[0] = Func0
f[1] = Func1
f[2] = Func2

Print f[0](10)
Print f[1](20)
Print f[2](30)

Function Func0:String(n:Int)
    Return "You passed "+n+" into Func0"
End Function

Function Func1:String(n:Int)
    Return "You passed "+n+" into Func1"
End Function

Function Func2:String(n:Int)
    Return "You passed "+n+" into Func2"
End Function

Expected behavior Works as expected in Vanilla Blitzmax. Fails with error in NG

Version information (please complete the following information):

Edit: seems the GitHub web parser doesn't like my source code. The Print statements should read You can see my post here https://www.syntaxbomb.com/index.php/topic,8280.msg347047941.html#msg347047941

GWRon commented 3 years ago

You should wrap your code into three backticks ... to avoid github issues eating [0]() as link :)

SuperStrict
Framework Brl.StandardIO

Local f:String(n:Int)[10]

f[0] = Func0
f[1] = Func1
f[2] = Func2

Print f[0](111)
Print f[1](222)
Print f[2](333)

Function Func0:String(n:Int)
Return "You passed "+n+" into Func0"
End Function

Function Func1:String(n:Int)
Return "You passed "+n+" into Func1"
End Function

Function Func2:String(n:Int)
Return "You passed "+n+" into Func2"
End Function
noroads2015 commented 3 years ago

Thanks GWRon. Wonder why it doesn't already do that when I click the "insert code" icon?

GWRon commented 3 years ago

Assume it is the "single tick" version - any maybe it has trouble with multi line code then :)

I assume this is a "bcc/bmk" bug, not a "bmx-ng" bug - so issue might have to be moved (by @woollybah). Just in case you wonder the ticket/issue moves to another repo :)

GWRon commented 3 years ago

It works when not utilizing the array index access:

Local fNonArray:String(n:Int)
fNonArray = Func0
Print fNonArray(111)
HurryStarfish commented 3 years ago

Looks related to bmx-ng/bcc/issues/444.