Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Circular type dependency resolution #806

Open
Hedwig7s opened this issue Sep 21, 2024 · 4 comments
Open

Circular type dependency resolution #806

Hedwig7s opened this issue Sep 21, 2024 · 4 comments
Labels
feature request New feature or request

Comments

@Hedwig7s
Copy link

Hedwig7s commented Sep 21, 2024

Right now, say you need a type from moduleB in moduleA, but moduleB depends on moduleA. This causes a circular dependency
This shouldn't theoratically be necessary as types can be represented as references and don't usually run any code with side effects as everything is predefined (which if a feature was added with this effect it could be an exception to this)
Teal already has the syntax local type x = require("module"). I suggest that requires using that syntax shouldn't cause circular dependencies and the checker should be able to resolve this. This would be similar to typescript's "import type".
Having to have a seperate "types" file is kind of messy in my opinion and shouldn't be necessary, and I feel this change could be heavily beneficial.
Hope to see this implemented!

@hishamhm
Copy link
Member

local type = require("module") should already be able to circumvent some circular dependency issues. Could you provide a minimal tiestcase with two example modules which illustrate the problem you're seeing? Thanks!

@hishamhm hishamhm added the feature request New feature or request label Sep 22, 2024
@Hedwig7s
Copy link
Author

local module = {}
local type testrecord = require("./test2")

function module.test(test:testrecord)
    print(test.a, test.b) -- circular require
end

return module
local record testrecord 
    a: string
    b: number
end

local test1 = require("test1")

test1.test({a = "hello", b = 42}) -- circular require

return testrecord

Note that placement seemed to have no effect, but with an integer type in place of a record placement seemed to slightly mess with errors, although it seemed to always have an error
Also pretty sure this applies to global types as well

@Hedwig7s
Copy link
Author

I do want to note this is not a necessary error as at no point does test1 use anything beyond simple type information from test2

@Hedwig7s
Copy link
Author

Also note interfaces (which don't have associated tables) also have the same error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants