compiler / type system bug: constructor` (1st argument) requires type X, got X
DerTee opened this issue · comments
I get the following error with the code below:
bug_test.lobster(10): error: `constructor` (1st argument) requires type `configuration`, got `configuration`
in bug_test.lobster(1): run() { }, context:undefined
The code:
run() // this call produces the error
class configuration:
resolution_x:int = 1024
resolution_y:int = 768
class context:
config:configuration = configuration {}
def run():
let context = context { }
print("Resolution: {context.config.resolution_x}, {context.config.resolution_y}")
// run() // this one works
I'm very unclear about this bug, but it happens reliably for and it's a problem dependent on two things:
- you must call run() from above the class and function definitions, if you call from below the definitions, it works
- you must use the context class, if you use the configuration class directly in run() then everything works fine, even if you call run() from above the class and function definitions
Thanks! I'll have a look :)
Fixed in a793841 (which hopefully fixes many similar bugs, and will make future ones more obvious/fixable).
In general, not all possible combinations of ordering will work with type inference, "define before use" as much as possible avoids errors (if configuration
or context
are changed to have generic parameters, it will still not work). But with this fix it should do a little better.