pschachte / wybe

A programming language supporting most of both declarative and imperative programming
MIT License
47 stars 6 forks source link

`_(T)` sometimes cannot find the module for `T` #424

Closed wnats closed 11 months ago

wnats commented 11 months ago

Compiling ll.wybe

constructors (T) empty | cons(head:T, tail:_(T))

def prepend(elt:T, xs:_(T)):_(T) = cons(elt, xs)

?xs:_(int) = empty
?ys = prepend(1, xs)

yields

typeIsUnique looking up module int
CallStack (from HasCallStack):
  error, called at src/AST.hs:657:31 in main:AST

This is resolved by:

wnats commented 11 months ago

Compiling this also yields the same error msg, with the same resolution (in this case replace color with ll.color)

constructors (T) empty | cons(head:T, tail:_(T))

type color {
    pub red | blk
}

def prepend(elt:T, xs:_(T)):_(T) = cons(elt, xs)

?xs:_(color) = empty
?ys = prepend(red, xs)

If color is defined in a separate module in the same directory, this would've worked

wnats commented 11 months ago

It seems not all ints are resolved to wybe.int

======================================================================
AFTER TYPE CHECK:
 Module ll(T)
  representation  : address
  public submods  : 
  public resources: 
  public procs    : ll.<0>
  imports         : use wybe
  resources       : 
  procs           : 

module top-level code > public {semipure} (0 calls)
0: () use !wybe.io.io:
    ll.<0>empty(?tmp#0:ll(wybe.int) @ll:5:14)
    foreign llvm move(tmp#0:ll(wybe.int), ?xs:ll(int) @ll:5:2)
    ll.<0>prepend(1:wybe.int @ll:6:15, xs:ll(int) @ll:6:18, ?tmp#1:ll(wybe.int) @ll:6:7)
    foreign llvm move(tmp#1:ll(wybe.int), ?ys:ll(wybe.int) @ll:6:2)
wnats commented 11 months ago

The root problem seems to lie in lookupType' when the type name is _ https://github.com/pschachte/wybe/blob/49bf8540148e5a55a905123a9836e6a392e5775e/src/AST.hs#L943-L946 where it does not resolve args as follows https://github.com/pschachte/wybe/blob/49bf8540148e5a55a905123a9836e6a392e5775e/src/AST.hs#L957-L975

Will do the fix shortly