Compiler error importing lua script file into table

There seems to be a bug in the pdc compiler when importing scripts into tables. If you import a script into a table value and another string in the lua source comes after a valid import, it'll try to find a script with that string's value and fail to build if it doesn't exist. This may be reproducible without tables, but this is the only way I've experienced it so far.

It's reproducible with a very simple project.

main.lua:

script = {
	{
		name = "intro",
		sequence = import "scripts/intro"
	},
	{
		name = "anyValue",
		sequence = import "scripts/ending"
	}
}

scripts/intro.lua, etc.:

return {{
	text = "Example value of some type"
}}

When building with pdc or a build task like the Nova extension:

error: main.lua:7: No such file: anyValue

Things I've observed:

  • Renaming keys has no effect
  • Adding explicit keys to the top-level table has no effect
  • An invalid value on the actual import call will trigger a compile error as it should, preventing the invalid compile error from being raised
  • Changing the anyValue value to a valid script path will not fail to compile but may be doing something weird with where the imported value ends up in the table (unconfirmed)
  • Removing the name key builds correctly with the imported values being set in the table
  • The compiler always reports an error on the last name key if all actual import calls are valid

This doesn't seem like a naming collision, as any of the string values here can be changed arbitrarily and the result is the same, but I'm not sure what else could cause this outside of a compiler bug.

According to this post import needs to be at the beginning of the line for it to work.

Maybe try putting it under your assignment line and see if that ugly hack works for you haha

1 Like

Thanks for looking at this! That limitation doesn't seem to be relevant anymore, and making that change doesn't affect the compile error. The documentation gives examples like print(import "a" or "nil") and using import in other expressions like that seems to work fine.

The issue can be worked around by doing something like:

local intro = import "scripts/intro"
...

script = {
    {
        name = "intro",
        sequence = intro
    },
    ...
}

...but that's definitely not as clean as importing directly into a table for things like this. I'm fairly sure it's a bug in pdc but since it has a simple workaround it's not too big of a deal.

1 Like

ohhhh okay, I think I see what's happening. To support the weird way we process imports at compile time I hacked up the parser a bit, and it didn't occur to me that it's possible to have more than one import in a statement. I'll have to dive back in and figure out how to handle this case. :diving_mask:

2 Likes