can-lehmann / owlkettle

A declarative user interface framework based on GTK 4
https://can-lehmann.github.io/owlkettle/README
MIT License
375 stars 13 forks source link

Spurious error when using iterator with static parameter. #25

Closed beef331 closed 10 months ago

beef331 commented 1 year ago

When using an iterator that uses a static parameter for the return type as following the DSL causes an error:

import owlkettle

type
  Thing = enum
    a, b, c
  MyType[T: static Thing] = object

iterator doThing(val: static Thing): MyType[val] = yield MyType[val]()

viewable App:
  a: int

method view(app: AppState): Widget =
  result = gui:
    Window:
      title = "Counter"
      defaultSize = (200, 60)
      Box():
        for val in doThing(a):
          Label(text = "hello")

brew(gui(App()))

/home/jason/.nimble/pkgs/owlkettle-#head/owlkettle/guidsl.nim(189, 23) Error: A nested proc can have generic parameters only when it is used as an operand to another routine and the types of the generic paramers can be inferred from the expected signature.

This might be resolved in closure generation by wrapping with when ident isnot static: var ident = ident. Or if the code is typed checking if the symKind is a var/let instead of just using all syms.

can-lehmann commented 10 months ago

Finally fixed this :smile:, turns out that using typeof instead of getTypeInst works.