teal-language/cyan

path normalization needed to avoid duplicated builds?

hishamhm opened this issue · 3 comments

I tried to run cyan build on teal-language-server without having other teal-types definitions around. I got this output (will paste it in full here, but point to a specific thing below)

cyan build      
    Error 5 type errors in src/rpc.tl
      ...    ./src/util.tl 2:29 no type information for required module: 'dkjson'
      ...    ./src/util.tl 73:19 cannot index a value of unknown type
      ...    src/rpc.tl 3:29 no type information for required module: 'dkjson'
      ...    src/rpc.tl 71:22 cannot index a value of unknown type
      ...    src/rpc.tl 83:21 cannot index a value of unknown type
     Info Type checked src/uri.tl
    Error 3 type errors in src/methods.tl
      ...    ./src/rpc.tl 3:29 no type information for required module: 'dkjson'
      ...    ./src/rpc.tl 71:22 cannot index a value of unknown type
      ...    ./src/rpc.tl 83:21 cannot index a value of unknown type
    Error 19 type errors in src/document.tl
      ...    /System/Aliens/LuaRocks/share/lua/5.4/cyan/command.tl 5:33 no type information for required module: 'argparse'
      ...    /System/Aliens/LuaRocks/share/lua/5.4/cyan/command.tl 34:23 unknown type argparse.Command
      ...    /System/Aliens/LuaRocks/share/lua/5.4/cyan/command.tl 55:34 unknown type argparse.Parser
      ...    /System/Aliens/LuaRocks/share/lua/5.4/cyan/command.tl 57:27 cannot index something that is not a record: argparse.Parser (an unknown type)
      ...    /System/Aliens/LuaRocks/share/lua/5.4/cyan/fs/init.tl 5:28 module not found: 'lfs'
      ...    /System/Aliens/LuaRocks/share/lua/5.4/cyan/fs/init.tl 18:24 cannot index a value of unknown type
      ...    /System/Aliens/LuaRocks/share/lua/5.4/cyan/fs/init.tl 26:43 cannot index a value of unknown type
      ...    /System/Aliens/LuaRocks/share/lua/5.4/cyan/fs/init.tl 124:11 cannot index a value of unknown type
      ...    /System/Aliens/LuaRocks/share/lua/5.4/cyan/fs/path.tl 112:15 cannot index a value of unknown type
      ...    /System/Aliens/LuaRocks/share/lua/5.4/cyan/fs/path.tl 170:15 cannot index a value of unknown type
      ...    /System/Aliens/LuaRocks/share/lua/5.4/cyan/fs/path.tl 176:15 cannot index a value of unknown type
      ...    /System/Aliens/LuaRocks/share/lua/5.4/cyan/fs/path.tl 182:15 cannot index a value of unknown type
      ...    /System/Aliens/LuaRocks/share/lua/5.4/cyan/fs/path.tl 194:30 assignment in declaration did not produce an initial value for variable 'err'
      ...    /System/Aliens/LuaRocks/share/lua/5.4/cyan/fs/path.tl 194:48 cannot index a value of unknown type
      ...    /System/Aliens/LuaRocks/share/lua/5.4/cyan/fs/path.tl 196:27 in return value: got <unknown type>, expected string
      ...    /System/Aliens/LuaRocks/share/lua/5.4/cyan/fs/path.tl 209:18 cannot index a value of unknown type
      ...    /System/Aliens/LuaRocks/share/lua/5.4/cyan/fs/path.tl 381:27 cannot index a value of unknown type
      ...    /System/Aliens/LuaRocks/share/lua/5.4/cyan/fs/path.tl 383:27 cannot index a value of unknown type
      ...    /System/Aliens/LuaRocks/share/lua/5.4/cyan/log.tl 9:36 no type information for required module: 'inspect'
    Error 2 type errors in src/handlers.tl
      ...    src/handlers.tl 4:28 no type information for required module: 'lfs'
      ...    src/handlers.tl 30:20 cannot index a value of unknown type
    Error 2 type errors in src/init.tl
      ...    ./src/handlers.tl 4:28 no type information for required module: 'lfs'
      ...    ./src/handlers.tl 30:20 cannot index a value of unknown type

What caught my attention was that src/rpc.tl and src/handlers.tl were compiled twice (once as src/ and once as ./src), leading to the duplicated error messages

(btw, all these cannot index a value of unknown type will go away in the next version of Teal because now unresolved requires are invalid rather than unknown; as a curiosity, this is the output with the bidi-inference branch — it's shorter, but as expected the issue I described above still happens)

    Error 2 type errors in src/rpc.tl
      ...    ./src/util.tl 2:29 no type information for required module: 'dkjson'
      ...    src/rpc.tl 3:29 no type information for required module: 'dkjson'
     Info Type checked src/uri.tl
    Error 14 type errors in src/document.tl
      ...    ./src/rpc.tl 3:29 no type information for required module: 'dkjson'
      ...    /System/Aliens/LuaRocks/share/lua/5.4/cyan/command.tl 5:33 no type information for required module: 'argparse'
      ...    /System/Aliens/LuaRocks/share/lua/5.4/cyan/command.tl 34:23 unknown type argparse.Command
      ...    /System/Aliens/LuaRocks/share/lua/5.4/cyan/command.tl 55:34 unknown type argparse.Parser
      ...    /System/Aliens/LuaRocks/share/lua/5.4/cyan/command.tl 57:27 cannot index something that is not a record: argparse.Parser (an unknown type)
      ...    /System/Aliens/LuaRocks/share/lua/5.4/cyan/config.tl 161:55 invalid key 'include_dir' in record 'args' of type command.Command.Args
      ...    /System/Aliens/LuaRocks/share/lua/5.4/cyan/config.tl 162:65 invalid key 'wdisable' in record 'args' of type command.Command.Args
      ...    /System/Aliens/LuaRocks/share/lua/5.4/cyan/config.tl 163:61 invalid key 'werror' in record 'args' of type command.Command.Args
      ...    /System/Aliens/LuaRocks/share/lua/5.4/cyan/config.tl 164:63 invalid key 'preload' in record 'args' of type command.Command.Args
      ...    /System/Aliens/LuaRocks/share/lua/5.4/cyan/config.tl 166:26 invalid key 'gen_compat' in record 'args' of type command.Command.Args
      ...    /System/Aliens/LuaRocks/share/lua/5.4/cyan/config.tl 167:26 invalid key 'gen_target' in record 'args' of type command.Command.Args
      ...    /System/Aliens/LuaRocks/share/lua/5.4/cyan/fs/init.tl 5:28 module not found: 'lfs'
      ...    /System/Aliens/LuaRocks/share/lua/5.4/cyan/fs/path.tl 194:30 assignment in declaration did not produce an initial value for variable 'err'
      ...    /System/Aliens/LuaRocks/share/lua/5.4/cyan/log.tl 9:36 no type information for required module: 'inspect'
    Error 1 type error in src/handlers.tl
      ...    src/handlers.tl 4:28 no type information for required module: 'lfs'
     Info Type checked src/methods.tl
    Error 1 type error in src/init.tl
      ...    ./src/handlers.tl 4:28 no type information for required module: 'lfs'

Off the top of my head i want to say that this is due to tl using package.path and directly substituting filenames into something like ./?.lua, I guess the hotfix solution would be to manually add both paths to the env.loaded, but maybe a better solution would be to introduce something like tl.searchers? (analogous to package.searchers) to interact with how tl finds modules?

I tried this again to see if teal-language/tl#538 fixed this by any chance, but with Cyan 0.1.0 I can't reproduce this, even with tl 0.13.2. So I guess this can be closed?