ISSUE DESCRIPTION Unknown constant in go dependencies conflicts with Lisette's built-in…
- User
ISSUE DESCRIPTION
Unknown constant in go dependencies conflicts with Lisette's built-in Unknown type The discordgo package defines a constant named
Unknown(used for unrecognized types/events), which conflicts with Lisette's built-in Unknown type. When Lisette generates bindings for discordgo, any function signature that uses Unknown as a type parameter is misinterpreted — the compiler sees the discordgo value Unknown in a type position, causing a resolve.value_in_type_position error.Error output:
🔴 Value in type position ╭─[go:github.com_bwmarrin_discordgo.d.lis:4693:46] 4692 │ /// Logger can be used to replace the standard logging for discordgo 4693 │ pub var Logger: fn(int, int, string, VarArgs<Unknown>) -> () · ───┬─── · ╰── expected type, found value 4694 │ ╰──── help: Only a type is allowed here · code: [resolve.value_in_type_position] 🔴 Value in type position ╭─[go:github.com_bwmarrin_discordgo.d.lis:4695:21] 4694 │ 4695 │ pub var Marshal: fn(Unknown) -> Result<Slice<byte>, error> · ───┬─── · ╰── expected type, found value 4696 │ ╰──── help: Only a type is allowed here · code: [resolve.value_in_type_position] 🔴 Value in type position ╭─[go:github.com_bwmarrin_discordgo.d.lis:4697:36] 4696 │ 4697 │ pub var Unmarshal: fn(Slice<byte>, Unknown) -> Result<(), error> · ───┬─── · ╰── expected type, found value 4698 │ ╰──── help: Only a type is allowed here · code: [resolve.value_in_type_position]Root Cause
discordgodefines a constant named Unknown (e.g. Unknown Locale). Lisette also has a built-in type named Unknown used to represent opaque/untyped Go values in bindings. When the binding generator emits Unknown in a type position, the name resolves to the discordgo constant value instead of the Lisette type, triggering the error.Expected Behavior
Lisette's built-in Unknown type should take precedence in type positions, or the binding generator should qualify/disambiguate imported names that shadow built-in types.
Reproduction
Add github.com/bwmarrin/discordgo as a dependency and run lis run. The error appears immediately during binding resolution without any user-written code.
import "go:fmt" import "go:github.com/bwmarrin/discordgo" const TOKEN = "token" fn main() { let _discord = try { discordgo.New("Bot" + TOKEN)? } fmt.Println("Hello world!") } - Assistant
I'll start by exploring the repository to understand its structure and locate the relevant code. Let's first look at the current directory.
- Assistant
Let me understand the repository structure first, focusing on the binding generator (likely in
bindgen/) and the built-in Unknown type. - Assistant
Let me explore the repository structure more to understand the binding generator and how Unknown type is handled.
- Assistant
Let me explore the crate structure to understand the project better.
- Assistant
The issue is about the binding generator (bindgen) for Go packages generating code where the
Unknownname is used in type positions, but it resolves to a Go constant calledUnknowninstead of Lisette's built-inUnknowntype.Let me explore the bindgen internal directory to understand how the binding generation works.
- Assistant
Let me search for "Unknown" in the codebase to understand how it's used.
- Assistant
Now I need to understand how the binding generator emits the
Unknowntype and how it's resolved. Let me look at the emitter code and the convert code more closely.Let me also check the prelude directory to understand what built-in types Lisette has.
- Assistant
Let me understand the issue better. The problem is that when the bindgen generates code for discordgo, the
Unknownconstant defined in discordgo conflicts with Lisette's built-inUnknowntype. The bindgen generates code that referencesUnknownas a type, but the compiler resolves it as the discordgo constant instead.Let me look at how the bindgen handles imports and name collisions.
- Assistant
Now let me look at the convert package to understand how types are being converted:
- Assistant
Now let me look at how the binding generator handles name collisions, particularly looking at the
import_collisiontest data and the emitter: - Assistant
Now let me look at how the emitter handles type names and particularly the
Unknownbuilt-in type: - Assistant
Let me look at the context around that line to understand what it's doing.
- Assistant
Let me look at how the binding generator handles name collisions in general, and see how it handles built-in type names.
- Assistant
Now I need to understand the actual problem. The bindgen generates bindings for discordgo where a constant named
Unknowngets exported. WhenUnknownis used in type positions (e.g.,VarArgs<Unknown>), the compiler resolves it as the discordgo constant value instead of Lisette's built-inUnknowntype. Let me look at how the Rust compiler handles built-in types. - Assistant
The problem is clear from the issue description. When Lisette generates bindings for discordgo, it encounters a Go constant named
Unknown(e.g.,discordgo.Locale("Unknown")). Lisette also has a built-in type namedUnknownused to represent opaque/untyped Go values. When the binding generator emitsUnknownin a type position (likeVarArgs<Unknown>), the name resolves to the discordgo constant value instead of the Lisette type.Let me look at how the emit code handles type conversion and where
Unknownis generated: - Assistant
Now I understand the problem better. Let me look at how the bindgen handles constants and what the generated output looks like. The issue is that when there's an exported constant named
Unknownin a Go package, the bindgen generates it as a constant in the Lisette binding file. Then when Lisette's built-in typeUnknownis used in type positions, it resolves to the constant instead of the type.Let me look at how constants are extracted and emitted:
- Assistant
Let me continue reading to see how constants are handled:
- Assistant
Let me read the full converters.go to understand how constants are handled and especially how types are resolved:
- Assistant
Let me now look at how the Rust compiler handles name resolution for types. The issue is that the bindgen creates a constant named
Unknownthat shadows Lisette's built-in typeUnknown: - Assistant
Let me search for where the error
resolve.value_in_type_positionis generated. - Assistant
Let me look at the code that produces this error to understand how type resolution works:
- Assistant
Now I understand the issue better. The bindgen generates a constant named
Unknownfrom the discordgo package, but Lisette also has a built-in type namedUnknown. When the compiler resolvesUnknownin a type position, it finds the discordgo constant instead of the Lisette type.Let me look at how the bindgen handles constants and type names to understand the fix:
- Assistant
Let me understand the resolution flow better. Let me look at the
resolve_type_nameandresolve_type_from_preludemethods: - Assistant
Now let me look at the resolve_type_name and resolve_type_from_prelude methods to understand how type resolution works:
- Assistant
Now I understand the flow. The issue is that when the bindgen generates a constant named
Unknown, it gets registered in the store. When the type resolver later encountersUnknownin a type position, it finds this constant (value) instead of Lisette's built-in type. Let me check what the prelude defines forUnknown: - Assistant
Let me look for where "Unknown" is defined in the prelude or core types. It might be a built-in type that's handled specially.
- Assistant
Let me look at the prelude typedefs for "Unknown":
- Assistant
Let me look at how the prelude defines types, especially "Unknown".
- Assistant
Let me understand how the bindgen handles the generation of constants and types. The key issue is that the bindgen generates
Unknownas a constant in the .d.lis file, which then conflicts with the built-inUnknowntype. Let me look at the full emission pipeline: - Assistant
Let me understand the issue better. The problem is that when the bindgen generates a constant named
Unknown(from the Go package), it creates a value namedUnknownin the Lisette code. However, Lisette also has a built-in type namedUnknownwhich is used in type positions. When the compiler tries to resolveUnknownin a type position, it finds the constant value instead of the built-in type, causing an error.Let me look at how the bindgen handles other built-in types to see if there's already a pattern for this.
- Assistant
Let me look at the builtins registration to understand how the
Unknowntype is registered: - Assistant
Let me look at the store implementation to understand how types and values are stored:
- Assistant
Let me look at the store's
get_typeandget_definitionmethods: - Assistant
Let me look at the lookup_qualified_name function:
- Assistant
Let me look at the lookup_qualified_name function:
- Assistant
Now I understand the issue better. Let me trace through the code flow:
- When the bindgen generates bindings for discordgo, it creates constants like
Unknown(from the Go package) - The Lisette compiler has a built-in type named
Unknownin the prelude - When the compiler encounters
Unknownin a type position (e.g.,VarArgs<Unknown>), it tries to resolve it - The resolution process calls
resolve_type_with_aritywhich first checksresolve_type_name resolve_type_namecallslookup_qualified_namewhich finds the constantUnknownfrom discordgo- Then
classify_non_type_nameis called which checks if the resolved name is a value (constant) instead of a type - If it's a value, it reports the
value_in_type_positionerror
The fix should be in the bindgen's emit logic. When the bindgen generates a constant whose name conflicts with Lisette's built-in types (like
Unknown), it should either skip that constant or rename it to avoid the conflict. Let me look at how constants are handled in the bindgen's emit logic: - When the bindgen generates bindings for discordgo, it creates constants like
- Assistant
Let me look at how the bindgen handles reserved names and see if there's already a mechanism for handling built-in type names:
- Assistant
Let me understand the flow better. The issue is in
resolve_type_with_arity. When it resolves a name, it checks arity. Both the discordgo constant and the built-in type have arity 0, so it returns the constant without checking the prelude. Let me look at how to fix this.There are two approaches:
- Fix in the resolver - when a resolved name is a value (not a type), fall back to prelude
- Fix in the bindgen - prevent emitting constants that conflict with built-in types
Let me look at how the bindgen handles this. Looking at the emitter.go, there's already a check for "basicTypes" that includes "Unknown":
- Assistant
Now I understand the full picture. The issue is that:
- The bindgen generates a constant named
Unknown(from discordgo) in the .lis file - The Lisette compiler has a built-in type also named
Unknown - When the compiler resolves
Unknownin a type position, it finds the discordgo constant first (not the built-in type) - This causes the "value in type_position" error
The fix should be in the bindgen. When it encounters a Go constant whose name is the same as a Lisette built-in type (like
Unknown), it should skip it or handle it differently. Let me look at how the bindgen decides to skip constants and see if there's already a mechanism for handling built-in type names. - The bindgen generates a constant named
- Assistant
Now I understand the full picture. Let me trace the exact flow:
- The bindgen generates a constant
Unknownin the discordgo bindings - When the compiler encounters
Unknownin a type position, it callsresolve_type_with_arity - This calls
resolve_type_name, which finds the discordgo constantUnknown - The arity matches (0 for both), so it returns the constant
- Then
classify_non_type_namedetects it's a value, not a type → error
The fix should be in
resolve_type_with_arity. When the resolution finds a value (not a type), and the name is a built-in type name, it should fall back to the prelude. Let me look at how to fix this properly.Let me check the existing test structure to understand how to create a test case:
- The bindgen generates a constant
- Assistant
Let me look at the store's get_type and get_definition methods to understand how type resolution works:
- Assistant
Now I understand the exact problem. Let me trace through the resolution:
resolve_type_with_aritycallsresolve_type_namewhich findsUnknownas a constant (value) from discordgo- The constant type has arity 0, which matches the expected arity, so it returns it immediately
- Then
classify_non_type_namesees it's a value, not a type → error
The fix should be in
resolve_type_with_arity: when the resolved name is a value (not a type definition), it should prefer the prelude type. Let me check how to detect this: - Assistant
Let me find the syntax crate.
- Assistant
Let me find the Definition type to see how definitions are stored.
- Assistant
Let me look at the Definition struct and DefinitionBody to understand what's a value vs a type.
- Assistant
Now I understand the full picture. The issue is in
resolve_type_with_arityinconvert.rs. When it finds a name that resolves to a value (not a type), and that name matches a built-in type, it should prefer the prelude type.Let me look at the exact method:
- Assistant
Now I understand the issue. Let me look at the
resolve_type_with_aritymethod more carefully: - Assistant
Let me look at the
resolve_type_with_aritymethod in detail: - Assistant
Now I understand the issue clearly. The
resolve_type_with_aritymethod finds the discordgo constantUnknown(a value), but when it has arity 0 (matching expected arity), it returns it directly. Theclassify_non_type_namethen correctly identifies it as a value in a type position. The fix should be: when a non-type definition (like a value/constant) shadows a prelude type, the prelude type should take precedence in type resolution.Let me implement the fix in
resolve_type_with_arity: - Assistant
Now I understand the problem. The
resolve_type_with_aritymethod inconvert.rsresolvesUnknownfrom the discordgo package (a constant), and since it has arity 0 (matching expected arity), it returns it directly. But this is a value, not a type.The fix should be: when the resolved definition is not a type definition (i.e., it's a value/constant), we should prefer the prelude type if one exists with the same name.
Let me implement the fix:
- Assistant
Now I understand the issue. The
resolve_type_with_aritymethod finds the discordgo constantUnknown(a value, not a type), and since its arity matches, it returns it directly. The fix should be: when the resolved name is a value (not a type definition), prefer the prelude type if one exists with the same name.Let me implement the fix:
- Assistant
Let me look at the
classify_non_type_namemethod to understand how it checks if something is a type vs a value: - Assistant
Now I understand the issue clearly. The
resolve_type_with_aritymethod at line 292 finds the discordgo constantUnknown(which is aValuedefinition). Since its arity matches (0 == 0), it returns it directly. Thenclassify_non_type_namecorrectly identifies it as a value, not a type, causing the error.The fix should be in
resolve_type_with_arity: when the resolved name is a value (not a type definition), prefer the prelude type if one exists with the same name. Let me implement this fix: - Assistant
Wait, I need to reconsider the logic. Let me re-read my fix carefully:
- Assistant
Now let me run the existing tests to verify my fix doesn't break anything:
- Assistant
Let me also run the full test suite:
- Assistant
Let me go back to the root directory and run tests:
- Assistant
Let me try running the specific tests:
- Assistant
Let me check the crate names.
- Assistant
Let me check the actual package name:
- Assistant
Let me run the tests with the correct package name:
- Assistant
Now let me check if there are integration tests I should also run. Let me look at the tests directory:
- Assistant
Let me look at the integration tests and see if there are any that might be affected by my change:
- Assistant
Let me also check if there are tests in the
testsdirectory that I should run. Let me look at the test structure: - Assistant
Let me check what's in the tests package:
- Assistant
Let me look at the UI tests that might be affected:
- Assistant
The suite test is passing. Let me now run the full suite without filtering:
- Assistant
A lot of tests failed. Let me check what kind of failures there are:
- Assistant
Let me check if the failures are pre-existing by looking at what the failures look like. Let me see if any of the failing tests are related to the
Unknowntype: - Assistant
Let me check if those failures are related to my change or are pre-existing:
- Assistant
The failures are pre-existing (same number of failures before my change). Let me restore my changes:
- Assistant
The
.newfiles are pre-existing snapshot failures. My change didn't affect the test results. Let me clean up those snapshot files and verify my fix works by checking the logic more carefully. - Assistant
Let me now verify my fix works by looking at the logic more carefully and making sure it handles the edge cases. Let me re-read the fix:
- Assistant
Now let me think about edge cases:
-
Normal case: User-defined type
Unknownin the same module →resolve_type_namefinds it, it's a type definition (is_type_def = true), so we skip the prelude check. ✓ -
The reported issue: discordgo constant
Unknown→resolve_type_namefinds it, it's NOT a type definition, so we check the prelude, findprelude.Unknown, return it. ✓ -
Go constant same name as non-prelude type: The prelude check fails, falls through to original logic. ✓
-
Qualified name (contains dot): We skip the prelude check. ✓
Let me verify the fix compiles:
-
- Assistant
The fix compiles. Let me also check if there's a UI test related to
value_in_type_positionto make sure I'm not breaking existing behavior: - Assistant
Let me also look at the existing test data for the
internalreffixture, which seems to have a comment aboutUnknown: - Assistant
Now let me look at how the
Unknownbuilt-in type is registered in the prelude. Let me check ifUnknownis registered as a prelude type: - Assistant
Let me look at the prelude.d.lis file to see how Unknown is defined:
- Assistant
Now I can see that
Unknownis indeed defined in the prelude as a type. My fix ensures that when the compiler encountersUnknownin a type position and it resolves to a value (like the discordgo constant), it falls back to the prelude type.Let me also check if there are any UI tests related to this error:
- Assistant
Let me look at one of these tests to understand what they test:
- Assistant
This test is checking that when a user writes
Nonein a type position, the compiler correctly identifies it as an enum variant (not a type) and suggests usingOptioninstead. My fix doesn't affect this test becauseNoneis not a prelude type - it's an enum variant ofOption. The test should still pass with my fix.Let me verify by running the UI tests:
- Assistant
Let me check the specific UI tests:
- Assistant
Let me also check if there are any tests that test the
Unknowntype in a type position: - Assistant
These failures seem to be pre-existing (10 failing out of those with "unknown" in the name). Let me verify:
- Assistant
Good - same failures exist without my change. My change doesn't break anything. Let me restore my changes:
- Assistant
Good - same 10 tests fail with and without my change. My change doesn't break anything. Let me also run the UI error tests to make sure:
- Assistant
All 608 UI error tests pass. My fix doesn't break any existing tests. Now let me review my change one more time:
- Assistant
My fix is minimal and targeted. Let me review the change one more time:
-
Root Cause: The discordgo package defines a constant named
Unknown(for unrecognized types/events). Lisette's bindgen generates this aspub const Unknown = ...in the.d.lisfile. Lisette also has a built-in type namedUnknownin the prelude (used to represent opaque/untyped Go values). When the compiler encountersUnknownin a type position (likeVarArgs<Unknown>), it resolves to the discordgo constant instead of the prelude type, causing a "value in type position" error. -
Fix: In
resolve_type_with_arity, when a name resolves to a value (not a type definition), prefer the prelude type with the same name. This ensures that built-in types likeUnknowntake precedence over Go-exported constants with the same name in type positions. -
Edge Cases:
-
- Assistant
Let me verify the final diff once more:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.