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!") }ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /lisette, current file: none) bash-$
- Assistant
I'll start by exploring the repository structure to understand the codebase and locate relevant files. Let me first check the current directory and look at the repository layout.
- Assistant
Let me explore the repository structure more thoroughly to understand how it's organized and find the binding generation code.
- Assistant
Let me explore the bindgen directory more closely since that's likely where the binding generation happens.
- Assistant
Let me understand the issue. The problem is:
discordgopackage defines a constant namedUnknown(e.g., forUnknown Locale)- Lisette has a built-in type named
Unknownused to represent opaque/untyped Go values in bindings - When the binding generator emits
Unknownin a type position, the name resolves to the discordgo constant value instead of the Lisette type, triggering aresolve.value_in_type_positionerror
The fix should ensure that Lisette's built-in
Unknowntype takes precedence in type positions, or the binding generator should qualify/disambiguate imported names that shadow built-in types.Let me explore the bindgen code to understand how types are resolved and how
Unknownis used. - Assistant
Let me look at the convert and emit directories to understand how types are processed.
- Assistant
Let me search for "Unknown" in the codebase to understand how it's used.
- Assistant
Let me look at the emit/emitter.go file to see what "Unknown" is used for.
- Assistant
Now let me understand the emit/emitter.go file better - this seems to be where the Lisette code generation happens.
- Assistant
Let me look at the emitter to understand how it handles types and how they are imported/qualified.
- Assistant
Let me look at how types are emitted, particularly how the emitter handles type references and whether it qualifies them with the package name.
- Assistant
Let me look at the types.go file in convert to understand how types are converted.
- Assistant
Let me examine the emitter more closely to understand how types are emitted and how the
Unknowntype is handled: - Assistant
Let me look at the full emitter to understand how types are emitted and how the
Unknowntype is handled. - Assistant
Let me check the Rust side to understand how the Lisette compiler resolves types.
- Assistant
Let me look at the prelude to understand what Lisette's built-in
Unknowntype is. - Assistant
Let me search for "Unknown" in the Rust codebase to understand how it's handled as a built-in type.
- Assistant
Let me search for
value_in_type_positionto understand how the error is generated. - Assistant
Let me look at the semantics/src/checker/registration/convert.rs file to understand how the error is triggered.
- Assistant
Let me look at the
classify_non_type_namefunction to understand what it does. - Assistant
Let me look at more of this function to understand what it returns and when it triggers the error.
- Assistant
Let me understand how the compiler resolves types:
- Assistant
Let me look at
resolve_type_nameto understand how it resolves names. - Assistant
Let me find where resolve_type_name is defined.
- Assistant
Let me look at that function.
- Assistant
Let me check how
Unknownis defined in the prelude and how it's registered: - Assistant
Let me look at the builtins registration:
- Assistant
Let me look at
resolve_type_with_arityto understand how types with arity are resolved: - Assistant
Let me look at
lookup_qualified_nameto understand how names are resolved in scope: - Assistant
Let me look at
lookup_qualified_namein the checker module. - Assistant
Let me check how other builtin types like
errorare handled in the binding generator: - Assistant
Let me look at how the prelude defines the
Unknowntype. Let me search the stdlib crate. - Assistant
Let me look at the prelude.d.lis file to see how the
Unknowntype is defined. - Assistant
Let me look at how the binding generator handles imports and see if there's a way to qualify types: Lisette>
- Assistant
Let me look at how the resolution works more carefully. The issue is that when
Unknownappears in a type position in a generated.d.lisfile, the resolver first finds theUnknownconstant from the imported Go package (discordgo) before finding the prelude'sUnknowntype.Looking at the
resolve_type_with_arityfunction:pub(super) fn resolve_type_with_arity( &mut self, store: &Store, type_name: &str, expected_arity: usize, ) -> Option<(String, Type)> { let arity_of = |ty: &Type| match ty { Type::Forall { vars, .. } => vars.len(), _ => 0, }; if let Some((qname, ty)) = self.resolve_type_name(store, type_name) { if arity_of(&ty) == expected_arity { return Some((qname, ty)); } if !type_name.contains('.') && let Some((pname, pty)) = self.resolve_type_from_prelude(store, type_name) && arity_of(&pty) == expected_arity { return Some((pname, pty)); } return Some((qname, ty)); } self.resolve_type_from_prelude(store, type_name) }And
resolve_type_name:pub(crate) fn resolve_type_name( &mut self, store: &Store, type_name: &str, ) -> Option<(String, Type)> { if self.scopes.lookup_type_param(type_name).is_some() { return None; } let qualified_name = self.lookup_qualified_name(store, type_name)?; let ty = store.get_type(&qualified_name)?.clone(); Some((qualified_name.to_string(), ty)) }And
lookup_qualified_name:pub(crate) fn lookup_qualified_name( &self, store: &Store, type_name: &str, ) -> Option<EcoString> { // Check prefixed imports first if let Some((prefix, simple_name)) = type_name.split_once('.') && let Some(module_id) = self.imports.prefix_to_module.get(prefix) && let Some(imported_module) = store.get_module(module_id) && let Some((qualified_name, _)) = self.resolve_in_imported_module(imported_module, simple_name) { return Some(qualified_name.into()); } // Check current module let module = store.get_module(&self.cursor.module_id)?; let qualified_name = Symbol::from_parts(&module.id, type_name); if module.definitions.contains_key(qualified_name.as_str()) { return Some(qualified_name.as_eco().clone()); } // Check unprefixed imports for imported_module_id in &self.imports.unprefixed_imports { if let Some(imported_module) = store.get_module(imported_module_id) { let qualified_name = Symbol::from_parts(imported_module_id, type_name); if imported_module .definitions .contains_key(qualified_name.as_str()) { return Some(qualified_name.as_eco().clone()); } } } None }So the problem is:
resolve_type_namelooks upUnknownin the current module and unprefixed imports- It finds
Unknownas a constant in the discordgo import (e.g.,go:github.com/bwmarrin/discordgo.Unknown) store.get_typereturns the type of that constant (which is some value type, not theUnknowntype)- Back in
resolve_type_with_arity, since the type was found (just not with the right arity), it returns it - The
classify_non_type_namefunction then detects it's a value, not a type, and reports the error
Wait, let me re-read the flow more carefully.
Looking at
resolve_type_with_arity:if let Some((qname, ty)) = self.resolve_type_name(store, type_name) { if arity_of(&ty) == expected_arity { return Some((qname, ty)); } if !type_name.contains('.') && let Some((pname, pty)) = self.resolve_type_from_prelude(store, type_name) && arity_of(&pty) == expected_arity { return Some((pname, pty)); } return Some((qname, ty)); // <-- This returns the discordgo value } self.resolve_type_from_prelude(store, type_name)So the issue is:
resolve_type_namefinds the discordgoUnknownconstant (a value)- Its arity doesn't match (it's 0, expected_arity is whatever)
- It tries to fall back to prelude, but the prelude's
Unknownalso has arity 0 - So it falls through to
return Some((qname, ty))— returning the discordgo value5. The caller then sees it's a value, not a typeWait, for the case in the error,Unknownappears without type parameters (e.g.,VarArgs<Unknown>). Soexpected_aritywould be 0. The discordgoUnknownconstant has arity 0. The preludeUnknowntype also has arity 0. So it returns the first one found.
The fix should be at the resolution level. When a name
Unknownis used in a type position, and it resolves to a value (not a type), the resolver should check the prelude for a type with the same name.Actually, looking at the flow more carefully:
In
resolve_type_with_arity:resolve_type_namefinds the discordgoUnknownconstant, returns(qname, type_of_constant)arity_of(&type_of_constant)==expected_arity— if expected_arity is 0, and the constant has arity 0, it returns immediately- If expected_arity is not 0, it checks the prelude, and if the prelude version matches, returns that
The problem is that when
Unknownis used without generics (arity 0), the discordgo constant also has arity 0, so it's returned directly without checking the prelude.Now, in the calling code in
convert.rs:if let Some((qname, ty)) = self.resolve_type_with_arity(store, type_name, params.len()) else { // type not found }; if let Some((kind, help)) = self.classify_non_type_name(store, &qualified_name, type_name) { // error: value in type position };So the fix needs to happen somewhere in this flow. There are a few possible approaches:
-
In the bindgen: Instead of emitting
Unknownas the type name, emit it with a prelude qualification likeprelude.Unknownso the resolver knows to look in the prelude, not in the imported package. -
In the resolver: When resolving a name in a type position, prefer a type from the prelude over a value from an imported module.
-
In the resolver: When
resolve_type_with_arityfinds a value (not a type) from a module, fall back to the prelude before returning.
Let me think about which approach is best. The issue description says:
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.
Option 1 seems simplest and most targeted: in the bindgen, when emitting
Unknownas a type, we should ensure it's distinguishable from a constant namedUnknownin the imported package.But wait, the issue is that
UnknownIS a built-in type in the prelude. The resolver should be finding it. Let me re-examine the resolution order:- Current module definitions
- Unprefixed imports
- (If not found, then) prelude
The problem is step 2 finds the discordgo
Unknownconstant, and it's returned as a hit before the prelude is checked.The cleanest fix would be in the resolver: when
resolve_type_with_aritygets back a value (not a type definition) from an imported module, and there's a type with the same name in the prelude, prefer the prelude version.Actually, let me re-read
classify_non_type_name:pub(super) fn classify_non_type_name( &self, store: &Store, qualified_name: &str, type_name: &str, ) -> Option<(&'static str, Option<String>)> { let definition = store.get_definition(qualified_name)?; if !matches!(definition.body, DefinitionBody::Value { .. }) { return None; } // ... it's a value, not a type }So it checks if the definition is a Value. If it is, it's considered a non-type name.
Now, the issue is in the resolution order. Let me look at the full flow for
convert_to_typemore carefully: - Assistant
Now let me understand the full flow. Let me look at the complete
convert_to_typemethod: - Assistant
Now I understand the issue clearly. Let me trace through the resolution logic.
When
Unknownappears in a type position (e.g.,VarArgs<Unknown>) in a.d.lisfile fordiscordgo:convert_to_typecallsresolve_type_with_arity(store, "Unknown", 0)- Inside
resolve_type_with_arity, it callsresolve_type_name(store, "Unknown") resolve_type_namecallslookup_qualified_name(store, "Unknown")lookup_qualified_namefindsgo:github.com_bwmarrin_discordgo.Unknown(the constant) in the current modulestore.get_typereturns the type of that constant (e.g.,Locale)- Back in
resolve_type_with_arity, arity 0 matches, so it returns the discordgo constant type classify_non_type_namedetects it's a value definition, not a type → error
The fix should be: in
resolve_type_with_arity, when the resolved name is a value definition (not a type), and the prelude has a type with the same name, prefer the prelude type.Let me check what
DefinitionBodyvariants exist: - Assistant
Let me find the DefinitionBody type.
- Assistant
Let me look at DefinitionBody enum to understand the different kinds of definitions.
- Assistant
Now I understand the full picture. Let me look at existing tests to see if there's a test for this kind of conflict.
- Assistant
Let me look at the bindgen tests to understand the testing approach.
- Assistant
Let me look at the predeclared_shadowing pass to understand how builtins are handled:
- Assistant
Now I understand the full picture. The issue is in the
resolve_type_with_aritymethod. When resolvingUnknownin a type position within a.d.lisfile that also defines a constant namedUnknown, the resolution finds the constant first (from the current module) and returns it. Since it's a value (not a type),classify_non_type_namecorrectly flags it as an error.The fix should be in
resolve_type_with_arity. When the resolved name is a value definition (not a type), and the prelude has a type with the same name, prefer the prelude type.Let me look at how the Store works to check definitions:
- Assistant
Now I understand the problem. Let me look at the full flow more carefully. The issue is in
resolve_type_with_arity- when the resolved name from the scope is a Value definition (not a type), and the prelude has a type with the same name, the prelude type should take precedence. Let me check howstore.get_definitionworks: - Assistant
Now I understand the problem and the fix. Let me look at what imports are available in the convert.rs file:
- Assistant
Now I understand the full picture. The fix should be in
resolve_type_with_arity- when the resolved name is a Value definition (constant/variable), and the prelude has a type with the same name that matches the expected arity, prefer the prelude type.Let me implement this:
- Assistant
Let me look at the exact lines I need to modify:
- Assistant
Let me also check how the type is stored for a value/constant definition:
- Assistant
Now I understand the full picture. Let me trace through the issue again:
- In the generated
.d.lisfile fordiscordgo, there's a constantUnknown(from Go'sdiscordgo.Unknownlocale constant) - When processing a type annotation like
VarArgs<Unknown>, the compiler tries to resolveUnknownas a type resolve_type_nameis called, which callslookup_qualified_namelookup_qualified_namechecks the current module first and findsgo:github.com_bwmarrin_discordgo.Unknown(the constant)store.get_type(&qualified_name)returns the type of the constant (e.g., the Locale type)- Back in
resolve_type_with_arity,arity_of(&ty)is 0 andexpected_arityis 0, so it matches and returns - Back in
convert_to_type,classify_non_type_namechecks if the resolved name is a Value definition, and it is → error
The fix should be: in
resolve_type_with_arity, when the resolved name from the scope is a Value definition, prefer the prelude type if it exists.Let me implement this fix:
- In the generated
- Assistant
Now let me verify the change looks correct:
- Assistant
Good, the change looks correct. Now let me build the project to make sure it compiles:
- Assistant
Great, the build succeeded. Now let me run the existing tests to make sure I didn't break anything:
- Assistant
Let me check if these test failures are pre-existing by reverting my change and running tests again:
- Assistant
The test failures are pre-existing (same number: 3572 passed, 1576 failed). This means my change didn't break anything. Now let me restore my change and verify it's still there:
- Assistant
Good. The test failures are pre-existing - same count (1576) both before and after my change. Let me now run the specific test suite for the semantics crate to make sure my change doesn't introduce any regressions:
- Assistant
All 54 tests in the semantics crate pass. Now let me look at the test fixtures to see if there are any related tests:
- Assistant
Let me look for tests related to the value-in-type-position error:
- Assistant
Let me look for relevant test fixtures that test this scenario.
- Assistant
Let me search for relevant test files more broadly.
- Assistant
Let me find the test files.
- Assistant
Let me look at the test structure and find where the
value_in_type_positionerror test might be: - Assistant
Let me find the resolve tests:
- Assistant
Let me look at the test structure more broadly.
- Assistant
Let me look for existing test fixtures that might be relevant.
- Assistant
Let me look at the
foreign_typed_constfixture since it seems related: - Assistant
Let me look for the test that relates to the semantics crate to check that the existing test suite still passes:
Now let me create a test to verify my fix works. First, let me understand the test infrastructure:
- Assistant
Let me look at the test infrastructure more to understand how tests are structured.
- Assistant
Let me look at the existing tests to understand how they test for the value_in_type_position error.
- Assistant
Let me look at the existing test snapshots to see if there are any that test the
value_in_type_positionerror: - Assistant
Let me look at these test snapshots to understand the existing behavior:
- Assistant
Let me look at the actual test that generates this error:
- Assistant
Let me check how enum variants are stored to understand if my change could affect them:
- Assistant
Let me verify my understanding by checking if the existing test
infer_not_a_type_unit_variant_preludestill works with my change. The key question is: are there cases where an enum variant is aValuedefinition AND there's a prelude type with the same name?Let me check what the prelude types are:
- Assistant
Good. Now let me verify that the existing tests still pass with my change. Let me run the full test suite again and compare:
- Assistant
Let me run the UI error tests to verify:
- Assistant
All 608 UI error tests pass. Let me also run the infer tests:
- Assistant
All 401 infer tests pass. Let me also verify the specific tests about value-in-type-position:
- Assistant
Let me look at the full test suite to make sure my change doesn't break anything:
- Assistant
Same 3572 passed, 1576 failed - exactly the same as before my change. The failures are pre-existing. My change didn't break anything.
Now let me check if the 1576 failed tests are the same ones. Let me look at one of the failed tests to understand why they fail:
- Assistant
Let me check if these are snapshot test failures (missing
.snap.newfiles): - Assistant
The test failures appear to be snapshot-related tests that need
.snap.newfiles created. These are pre-existing failures unrelated to my change (since the same count of 1576 failures appears both with and without my change). Let me verify this: - Assistant
Let me check what's going on with the failing tests. Let me look at one specific failing test.
- Assistant
The failures are pre-existing snapshot mismatches, not related to my change. Let me now create a test to verify my fix works for the specific issue described. Let me first look at how UI tests work:
- Assistant
Now let me verify my change is correct by looking at the diff:
- Assistant
The change looks correct and minimal. Let me now verify the fix with a more comprehensive test. Let me check if there are any related existing tests that specifically test the
Unknowntype usage: - Assistant
The test failures are all pre-existing snapshot mismatches (
.snap.newfiles being generated). Let me verify this is consistent: - Assistant
Let me also verify that the
.snap.newfiles were already present before my change (confirming these are pre-existing failures): - Assistant
Good - the 1573
.snap.newfiles already exist, confirming these are pre-existing failures. My change doesn't add or remove any.snap.newfiles.Now let me verify the final diff:
- Assistant
Now let me review the final diff. The change is minimal and targeted. Let me verify the semantics crate builds cleanly:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-lunaCompare side by side →
- gpt-5.6-lunaCompare side by side →
- gpt-5.6-lunaCompare side by side →