Luau require() tracer issue, can't construct partial "paths" with instances in Old and New Solver

Description

Currently, require doesn’t seem to understand “types”. If I defer a type to a Folder, require won’t actually account for it.

local LocationA = fixedLocation -- A fixed location to a Folder. The Folder contains "Folder.ModuleScript"
local Module: typeof(require(LocationB.ModuleScript)) = require(LocationA.ModuleScript)

I can’t do this, it will result into any. This is for the Old and New solver.

Nor can I have this

local test = {}
test.Folder = game.ServerStorage.Folder

local a = require(test.Folder.ModuleScript)
-- "a" will result into "any"

 

local Folder = game.ServerStorage.Folder
require(Folder.ModuleScript)
-- Result is good
local Folder: typeof(game.ServerStorage.Folder)
require(Folder.ModuleScript)
-- Result is bad

 

You can only use typeof with require if you provide it a more fixed path.

Summary
local Loc = game.ReplicatedStorage.Folder

local test: typeof(require(game.ServerStorage.Folder.ModuleScript)) = require(Loc:WaitForChild("ModuleScript"))
-- We are doing require on the ModuleScript directly

 

Re-production Steps

Check out the Test Place File in the Private Message.

 

 

Expected Result

You may wonder. Why do I do this?

local Folder = game.ReplicatedStorage.FolderB :: typeof(game.ServerStorage.FolderA)

What if my development Folder is located at game.ServerStorage.FolderA, but will later be brought to a different location, which is game.ReplicatedStorage.FolderB
There’s so many Modules in there, and all I want to do, is to define a Location where they are, to use them with require, but get the actual location for the actual script that is going to compile and run. (type annotations is not the script)

  • require() only allows me to do the full path to the real path.
  • require() I can store the real folder with the module in a variable and access the ModuleScript that I want to require, with require() as well
    • But I can’t do that with the folder that yet has to receive a module and I can’t re-direct it with type annotations. However, the autocomplete for the Folder itself has no issues.

 

Actual Result

A private message is associated with this bug report

2 Likes

This is just an acknowledgment announcement!

We’ve filed a ticket into our internal database for this issue, and will come back as soon as we have updates!

Thanks for flagging!

We have implemented a solution to extend require support for cases like local Folder = game.ReplicatedStorage.FolderB :: typeof(game.ServerStorage.FolderA)
It should be available in the future update.

Having said that, we are focusing more on recently introduced require-by-string system and will not focus on supporting complicated require scenarios like accessing values from table fields or symbolic execution of function calls.

1 Like

oh, because I was about to make a pull request :sob:

because I also fixed it

but that’s very cool

 

Now, can I tell you about my idea with how the require tracer could support ObjectValue’s Value Property? :thinking:

Tracing through ObjectValue could be implemented in the private Roblox module resolver callback.
That part can not be contributed in open-source Luau.

1 Like

Wait, if the private Roblox module resolver has a callback.

Does the Luau repository call something, that will invoke that private callback? Because, I don’t think I’ve seen where that would be in the repository.

Because I was wondering if the Luau repository would expose things that third-party (e.g. Roblox) could use to alter the behavior so it works with custom stuff like the DataModel from Roblox.

Edit:
Oh, I see

info = fileResolver->resolveModule(context, expr);