tokay-lang / tokay

Tokay is a programming language designed for ad-hoc parsing, inspired by awk.
https://tokay.dev
MIT License
236 stars 7 forks source link

bug: Generic use before definition fails #126

Closed phorward closed 7 months ago

phorward commented 7 months ago

This works:

Hello : @<World> mode = "standard" {
    'Hello' _ Expect<Self>  print(mode)
    World  print(*World)
}

Earth : @{
    'Earth'
}

HelloEarth : @{
    Hello<Earth>("modified")
}

HelloEarth

#---
#HelloHelloEarth
#---
#<parselet Earth>
#standard
#modified

This fails:

HelloEarth : @{
    Hello<Earth>("modified")
}

Hello : @<World> mode = "standard" {
    'Hello' _ Expect<Self>  print(mode)
    World  print(*World)
}

Earth : @{
    'Earth'
}

HelloEarth

#---
#HelloHelloEarth
#---
#<parselet Earth>
#standard
#modified

Example call:

$ cargo run -- tests/generics.tok -- HelloHelloEarth
    Finished dev [unoptimized + debuginfo] target(s) in 0.05s
     Running `target/debug/tokay tests/generics.tok -- HelloHelloEarth`
Line 2, column 5: Cannot create instance from 'Hello'
Line 2, column 5: Cannot create instance from 'Hello'
Line 2, column 5: Cannot create instance from 'Hello'
Line 2, column 5: Cannot create instance from 'Hello'