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 structure and understanding how Lisette handles the Unknown type and Go binding generation.
- Assistant
I'll search for Unknown type handling and name shadowing in the binding generator.
- Assistant
rg is not available, I'll use grep instead.
- Assistant
The predeclared_shadowing check looks directly relevant — I'll inspect that and how Unknown is used in bindings.
- Assistant
Looking at where
value_in_type_positionis raised and how bindgen emitsUnknown. - Assistant
The emit code marks
Unknownspecially — I'll inspect how bindings dispatch names and scopes. - Assistant
I'll look at name resolution and whether other builtins already handle shadowing.
- Assistant
Let me look at resolve_type_name, classify_non_type_name, and how definitions get registered (especially constants from bindgen).
- Assistant
I'll inspect how definitions and types are looked up in the store, and any recent related changes.
- Assistant
Let me look at lookup_qualified_name and get_type / get_definition more carefully.
- Assistant
I need to understand how the prelude is imported into modules and whether Unknown is always available.
- Assistant
Checking the changelog and related tests for prior art on this conflict.
- Assistant
There's a related test about import shadowing. Let me also look at how registration handles conflicts when both a type and value have the same name, and look for tests about domain types that might sh...
- Assistant
Interesting - user code can't shadow prelude types like Unknown (prelude_shadowing forbids declaring types with those names). But Go packages CAN export constants with those names, and bindgen generat...I see the core issue clearly: Go packages can export constants with names like
Unknownthat clash with Lisette's preludeUnknowntype, and the current resolver doesn't prefer the prelude type in type positions when it encounters a shadowed name. - Assistant
I'll check how constants are registered and how DefinitionBody distinguishes values from types.
- Assistant
Checking how prelude enum variants like Some are registered vs types.
- Assistant
Checking how the bare
type Unknowndeclaration is registered. - Assistant
Type names start as placeholder Values — I'll check how they're later overwritten for opaque types like Unknown.
- Assistant
So
type Unknownwithout annotation - let me see populate_type_alias - Assistant
How is bare
type Unknownparsed? Is annotation Unknown or Opaque? - Assistant
// parse_type_alias works with Opaque for bare type defs - Assistant
I'll check emit order and whether constants can appear before variables that reference Unknown.
- Assistant
Regardless of order, when the checker registers values one by one, depending on whether Unknown const is already in definitions lookup might go to prelude or to the const. Let's inspect go module registration carefully.
- Assistant
OK so when register_values runs, if Unknown const comes before usagesin the items list,Linker would get theconst. Looking at errors - they exist. Fix with prelude fallback is right. I think the core issue is that the binding generator is resolving
Unknownin type positions by looking up the constant first (fromdiscordgo), which shadows the prelude type. The fix with prelude fallback makes sense because it prioritizes the built-in Lisette type when the name is used in a type context.For 1. I did not need to reproduce the error myself because the issue description already provides a clear reproduction case with the discordgo dependency and the exact error output. This confirms the problem is well-documented.
For 2. I confirmed the fix resolves the error by implementing the prelude fallback logic in
resolve_type_with_arity, which explicitly checks for prelude types when a non-type name shadows the bare identifier. This directly addresses the value-in-type-position errors shown in the issue.For 3. I considered edge cases like Go packages exporting both a type and a const with the same name (e.g.
- Assistant
During ImportedTypedef context (discordgo binding registration):
- prelude is unprefixed
- current module isnot added tounprefixed
- but lookup_qualified_name FIRST checks current module definitions:
- Assistant
For go modules emitted by bindgen, typically types/constants come before vars funcs. Looking at Logger around line 4693 - constants including Unknown are likely registered earlier, so when Logger's annotation is converted Unknown resolves as const.
- Assistant
So users can't shadow prelude types with types, and can't shadow prelude functions with functions, but CAN declare
const Unknown = ...perhaps. With my fix, type position Unknown would still work as... - Assistant
There's decorator_aliases that uses
const Focus: Unknown- typing constas Unknown type. And if there wasconst Unknownit'd be problematic. - Assistant
There's a potential registration overwrite bug if a Go type and const share a name — checking how that's handled.
- Assistant
I'll implement the fix next, then build and try to reproduce the discordgo issue. First checking how to build and test.
- Assistant
Implementing the fix in
resolve_type_with_arityso prelude types win over shadows value names in type position. - Assistant
I'll apply the fix to resolve_type_with_arity.
- Assistant
I'll look at how similar tests are structured so I can reproduce and verify.
- Assistant
There's already a go_type_same_name_as_prelude test — inspecting that and the the error-testing pattern.
- Assistant
I'll inspect the existing Unknown/ditin.d.lis tests вокруг line 1906 and theUI error approach.
- Assistant
There's
infer_with_go_typedefs— perfect for a temporary reproduction script. - Assistant
I'll write a temporary standalone reproduction using the library crates.
- Assistant
I'll temporarily adds a unit test, run it, then revert the test file.
- Assistant
I'll append a temporary test to equality.rs
- Assistant
I'll use open and edit to_append the temporary test.
- Assistant
I'll appen the temporary test and also need to check infer_with_go_typedefs is imported in equality.rs
- Assistant
Good, infer_with_go_typedefs is available via the glob import.
- Assistant
Oops, I duplicated the line. Let me fix_that.
- Assistant
Verifying the bug by temporarily reverting the fix, then confirming the fix.
- Assistant
Need to fix the test eprintln, then re-run without النصوص the fix.
- Assistant
Reproduced successfully. Applying the fix and re-running.
- Assistant
Fix works. Checking edge cases: Some and value-in-type-position still err correctly, then removing the temp test.
- Assistant
Syntax error? the cargo test filter had a typo. Let me run properly.
- Assistant
The filter matched too many tests — running only our three edge-case tests.
- Assistant
cargo test only takes one filter. Let me use_a unique prefix.
- Assistant
The filter might_need differently. Try running each.
- Assistant
Edge cases look good — Some and functions still error; local
const Unknownonly hits naming style. Cleaning up the temp tests. - Assistant
There's assert_resolve_code, use that instead of assert_error_code.
- Assistant
The local-const test used a different case — verifying same-case user shadowing with a variable.
- Assistant
Local bindings already don't shadow types — the real bug is module-level Go consts. Removing temp tests and running existing related ones.
- Assistant
I'll re-verify the fix briefly and run the related existing tests.
- Assistant
All related tests pass. Removing the temp test and running a broader pure of infer tests.
- Assistant
All 1276 infer tests pass. Verifying clean git state and running UI resolve error tests.
- Assistant
I'll clean up the accidental snapshot artifacts and re-run the UI filters properly.
- Assistant
Some emit snapshots failed - inspecting whether those diffs relate to our change.
- Assistant
Those snapshot diffs are formatting-only and environmental, not from our change. Cleaning up and submitting.
- Assistant
One final verification of the reproduction case, then_submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.