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
Let me analyze this issue. The problem is that when Lisette generates bindings for the
discordgoGo package, theUnknownconstant defined in that package conflicts with Lisette's built-inUnknowntype. This causes a "value in type position" error because the compiler resolvesUnknownto the discordgo constant instead of the Lisette type.Let me start by exploring the repository structure to understand how the codebase is organized and find the relevant files.
Assistant
Let me explore more to understand the repository structure better, especially looking for binding generation and name resolution code.
Assistant
Let me look at the bindgen code since that's likely where the binding generation happens and where the Unknown type handling would be.
Assistant
Now let me search for where "Unknown" is used in the codebase, particularly in the binding generation and compiler resolution logic:
Assistant
Let me look at the emitter code where "Unknown" is mentioned:
Assistant
Now I can see the
isInferredNamedTypefunction has"Unknown": truein thebasicTypesmap. This is used to determine if a constant's type should be inferred. But the main issue is about name resolution when a Go package defines a constant namedUnknown.Let me now look at the Rust compiler side where name resolution happens:
Assistant
Now I can see the issue. When
resolve_type_with_arityis called withUnknown, it callsresolve_type_namewhich finds theUnknownconstant from the discordgo package (a value, not a type), then callsclassify_non_type_namewhich detects it's a value and emits thevalue_in_type_positionerror.The issue is that the builtin
Unknowntype should take precedence over imported values with the same name. Let me look at how the type name resolution works:Assistant
Let me look at
lookup_qualified_nameto understand how names are resolved:Assistant
Now let me look at
resolve_type_with_aritymore carefully. The issue is that when a Go package defines a constant namedUnknown, thelookup_qualified_namefinds it first in the imported module, but it's a value, not a type. The builtinUnknowntype inpreludeshould take precedence in type positions.Let me look at how the prelude Unknown is defined:
Assistant
Now I understand the issue better. The problem is in
resolve_type_with_arity. When it resolves the type nameUnknown:- It first calls
resolve_type_namewhich useslookup_qualified_nameto find definitions in the current module and imported modules - If a Go package (like discordgo) defines a constant
Unknown, it will be found in the imported module's definitions - The resolution succeeds but
classify_non_type_namedetects it's a value definition, not a type - This triggers the
value_in_type_positionerror
The fix should be: when resolving a type name, the prelude builtin types should take precedence over imported value names. Let me look at the
resolve_type_with_arityfunction more carefully:- It first calls
Assistant
Now I see the problem clearly. The
resolve_type_with_arityfunction:- First tries
resolve_type_name(store, type_name)which looks in the current module and imported modules - If found, it checks if the resolved thing is actually a type or a value via
classify_non_type_name - If the name resolves to a value (like the discordgo
Unknownconstant), it emits thevalue_in_type_positionerror
The issue is that for builtin/prelude types like
Unknown, when the name resolves to a value from an imported Go module, we should check if there's a prelude type with the same name and use that instead.Let me look at the logic in
convert_to_typewhereclassify_non_type_nameis called:- First tries
Assistant
Now I understand the flow. The key insight is:
resolve_type_with_arityfirst callsresolve_type_namewhich looks up in the current module and imported modules- If it finds a name but the definition is a value (not a type), then
classify_non_type_nameis called and the error is emitted - The fallback to prelude only happens if the resolved type has a different arity than expected
The fix should be: when
resolve_type_nameresolves to a value (not a type) for an unqualified name, we should check if the prelude has a type with that name and use the prelude type instead. This is especially important for builtin types likeUnknown.Let me look at how
resolve_type_nameworks and understand what qualifies as a "type" vs a "value":Assistant
Now let me understand the approach better. The issue is in
resolve_type_with_arity. When it callsresolve_type_name, it finds a definition forUnknownin the discordgo module (which is a value/constant). Thenclassify_non_type_namedetects it's a value and emits the error.The fix should be: in
resolve_type_with_arity, after finding a name that resolves to a value (not a type) in an imported module, we should fall back to checking the prelude for builtin types before giving up.Let me look at how this should work:
Assistant
Now I understand the structure. Let me look at how to fix this. The key is in
resolve_type_with_arity. When the name resolves to something in an imported Go module butclassify_non_type_namedetermines it's a value (not a type), we should try the prelude before emitting an error.Let me look at the flow again in the
convert_to_typefunction:Assistant
Now I have a clear understanding. The fix should be: when
classify_non_type_namedetects that the resolved name is actually a value (not a type), we should check if this is an unqualified name and if the prelude has a type with that name. If so, use the prelude type instead.The best place to fix this is in
resolve_type_with_arity. Currently:- It first tries
resolve_type_name(current module + imports) - If found but wrong arity, it falls back to prelude
- If not found at all, it falls back to prelude
But the issue is: when
resolve_type_namefinds a name that is a value (not a type), we should also fall back to the prelude. Let me modify the logic:- It first tries
Assistant
Now let me look at
classify_non_type_nameto understand what makes something a non-type name:Assistant
Now I have a clear understanding. The
classify_non_type_namefunction returnsSomewhen the resolved definition's body isDefinitionBody::Value { ... }(i.e., it's a constant, variable, or function) and its type is not a self-referential type alias.The best fix is to modify
resolve_type_with_arityto check if the resolved name is actually a type definition (not a value definition). If it's a value definition for an unqualified name, we should fall back to the prelude.Let me implement the fix:
Assistant
Now let me create the fix. The approach is to modify
resolve_type_with_arityso that when it finds a name that resolves to a value definition (not a type definition) from an imported Go module, and the name is unqualified, it should fall back to the prelude first before returning the value definition.Assistant
Now I need to understand the fix better. The issue is that when
resolve_type_namefinds a definition forUnknownin the discordgo module, it returns the type of that definition. But the definition body isValue, not a type definition. Soclassify_non_type_namecorrectly identifies it as a value in type position.The fix should be: when resolving a type name that doesn't contain a dot (unqualified), and the resolved definition is a value (not a type), we should check if the prelude has a type with that name and prefer the prelude type.
Let me implement this fix:
Assistant
Let me edit the file directly:
Assistant
Now I can see the full file. Let me create the fix by editing the
resolve_type_with_arityfunction. The fix should check if the resolved name is a value definition (not a type) and if so, fall back to the prelude for unqualified names:Assistant
Now let me apply this fix to the file:
Assistant
I need to replace the function in the file. Let me use sed to do this carefully.
Assistant
Let me verify the change was applied correctly:
Assistant
The change looks correct. Now let me verify the file compiles:
Assistant
It's downloading dependencies. Let me wait for the compilation to finish:
Assistant
The code compiles successfully. Now let me check if there are any existing tests related to this functionality:
Assistant
Let me look for tests related to type resolution, the Unknown type, or Go bindings:
Assistant
Let me look at the test structure and see if there are any tests related to type resolution or shadowing of built-in types. I should also look for Rust tests in the semantics crate.
Assistant
Let me look for how the UI tests are run and if there's a test for the shadowing case:
Assistant
End
Assistant
Now I understand the test structure better. Let me look for tests that involve the prelude or Go bindings:
Assistant
Let me now run the existing tests to make sure my change doesn't break anything:
Assistant
Many tests failed. Let me investigate what's going on - these failures might be related to my change. Let me look at a specific failing test:
Assistant
None
Assistant
hardthink>
Assistant
Let me look at the failing tests. Since the issue is with emit tests (Go code generation), I suspect the failures might be related to snapshot tests that are failing because the environment doesn't have Go or something else. Let me run a specific test to see the error:
Assistant
Assistant
The tests are failing because snapshots are being stored. This means the test snapshots are out of date or missing, not because my code change broke anything. Let me check if this is a pre-existing condition by reverting my change and running the tests again:
Assistant
The tests are failing even without my change, so this is a pre-existing condition with the test environment (likely missing snapshot files). Let me restore my changes and run the infer tests instead, which seem to pass:
Assistant
The tests are failing because snapshot files are missing — this is a pre-existing environment condition, not caused by my change. The infer tests pass (1276 passed).
Let me verify my fix is correct and check the diff:
Assistant
The fix looks good. Now let me also run the UI tests (which test error messages) to make sure they pass:
Assistant
All UI error tests pass. Let me also verify my understanding of the fix by checking if there are any existing tests that might test similar behavior or that might need updating:
Assistant
Let me continue verifying the fix and run more tests to ensure everything is working correctly.
Assistant
The
Unknownreferences I see in the tests are for testing type not found errors, not the specific issue we're fixing. TheUnknownin the issue is a built-in Lisette type that gets shadowed by a Go constant.Let me verify my fix handles edge cases:
- When a Go package defines a constant named
Unknown(or any other prelude type likeint,string,Slice, etc.) - The prelude type should take precedence in type positions
- The fix only applies to unqualified names (no
.in the type name) - The fix only applies when the resolved definition is a
Value(not a type definition) - The fix only applies when the prelude has a type with that name and the arity matches
- When a Go package defines a constant named
Assistant
These tests are about using
Unknownin invalid contexts (like const annotations or bound positions), not about the shadowing issue. My fix shouldn't affect these tests.Let me verify the current state of my change and make sure it's correct:
Assistant
The fix looks correct. Let me run the full test suite one more time to confirm my changes don't break anything. I'll focus on the tests that are likely to pass (infer, syntax, parsing, etc.):
Assistant
Let me check if the failing tests are pre-existing by looking at what category they are:
Assistant
The UI error tests all pass. The failures seem to be in the
spec::emittests which are snapshot-based and are failing because the snapshot files are missing (a pre-existing environment issue, not caused by my change).Let me run the UI lint tests and other non-emit tests to make sure they pass:
Assistant
Let me run the spec::infer tests as well to make sure my change doesn't affect type inference:
Assistant
All 1276 inference tests pass. Let me also run the spec::build tests to see if there are any issues with my change:
Assistant
Let me verify this is a pre-existing issue by checking if Go is installed and if the tests were failing before my change:
Assistant
Go is not installed, which explains why the build and emit tests are failing - they require Go to be present. This is a pre-existing environment condition, not related to my change.
Let me verify my change is correct by checking if all the tests that don't require Go pass:
Assistant
All parsing tests pass. Let me run the semantics-related tests:
Assistant
All semantics tests pass. Now let me review my fix one more time and think about edge cases:
Assistant
My fix looks correct and comprehensive. Let me now create a summary of the changes and verify the fix one more time:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.