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!") }Interface
No new interfaces are introduced.
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
Let me start by exploring the repository structure to understand what we're working with.
Assistant
Let me see what an existing generated bindgen file looks like:
Assistant
Now let's understand where
Unknownis defined:Assistant
Now let's look at the bindgen code to understand how the Unknown type is generated:
Assistant
Now let's understand the issue. The error is in
resolve.value_in_type_position. Let me look at the Lisette resolver to understand how Unknown is resolved:Assistant
Now I understand the issue. When
Unknownis in a type position, the resolver first tries to resolve it as a type name. Let me trace through what's happening:Assistant
Now I understand the issue. The
lookup_qualified_namefunction looks up the name in imported modules and finds the discordgoUnknownconstant first because Go's import order/shadowing makes this conflict happen. Let me explore the discordgo package:Assistant
Now, let me understand how
unprefixed_importsandprefix_to_moduleget populated, and what is the prelude:Assistant
Now I understand. Let me look at the resolution order more carefully:
Assistant
I see. Now I understand. The order is:
- Module's own definitions
- Unprefixed imports (which include
preludeand any imported modules)
Now the issue is, when the discordgo package defines a constant
Unknown, in the discordgo.d.lis file, the module's definitions will includeUnknownand the prelude'sUnknownwill be shadowed.Wait, let's re-read the issue. The error is about parsing
Unknownin a TYPE position. Let me look at how those files get generated - specifically the discordgo.d.lis file:Assistant
Now I understand the full picture. Let me look at the discordgo
locales.goreference from the issue and understand what scenarios cause the issue.Assistant
Let me look at the bindgen "external collision" code:
Assistant
Now let me look at the actual generated files to understand what discordgo.d.lis looks like (let me see if there's one cached):
Assistant
Now let me check the bindgen's existing tests to understand what's tested:
Assistant
Let me reproduce the issue first. Let's set up a small test case to understand the issue better. Let me first try to reproduce the error:
Assistant
Let me look at how the discordgo package generates Unknown in a type position. Let me look at the discordgo source code:
Assistant
Now let's look at the discordgo's Logger, Marshal, Unmarshal:
Assistant
Good, now I have a better understanding. Let me understand the actual issue:
When the bindgen generates code for the discordgo package, it emits:
pub var Logger: fn(int, int, string, VarArgs<Unknown>) -> ()pub var Marshal: fn(Unknown) -> Result<Slice<byte>, error>pub var Unmarshal: fn(Slice<byte>, Unknown) -> Result<(), error>
These signatures have
Unknownin type positions, which makes sense because Go'sinterface{}(which isany) maps to Lisette'sUnknown.But also, the discordgo package has:
pub const Unknown: Locale = ""
When this file is registered as a module, the constant
Unknownis added as a VALUE in the module'sdefinitionsmap. When the resolver tries to resolveUnknownin a type position, it finds the discordgo constant first (sincelookup_qualified_namechecks the current module's definitions first).So now the question is: how should this be fixed?
The issue suggests two options:
- Lisette's built-in Unknown type should take precedence in type positions
- The binding generator should qualify/disambiguate imported names that shadow built-in types.
Let me look at how the prelude is handled. Looking at the issue more carefully - the prelude types should take precedence but they don't because the module's own definitions are checked first.
Let me trace through this:
lookup_qualified_nameforUnknownin the discordgo module- It checks the discordgo module's definitions - finds
discordgo.Unknown(the constant) - Returns
discordgo.Unknown resolve_type_namereturns the type but it's actually a value definition- The error
value_in_type_positionis raised
Let me look more closely at the
classify_non_type_namefunction - it has a check that ignores self-references:if body.get_qualified_id().is_some_and(|id| id == qualified_name) { return None; }But that doesn't help here because
discordgo.Unknownis a constant whileprelude.Unknownis the type. The qualified name is what gets returned.Now let me think about the actual fix. The issue is that we need to check if the resolved name is actually a type (from its definition body) before returning it, and if not, prefer the prelude.
Let me look at this more carefully. Actually, looking at the flow:
resolve_type_with_arity(store, "Unknown", 0)is called for a type position- It calls
resolve_type_name(store, "Unknown") - That calls
lookup_qualified_name(store, "Unknown")which:- Checks the current module's definitions → finds
discordgo.Unknown(the constant) - Returns this
- Checks the current module's definitions → finds
- The returned qualified name is for the constant, not the type
- Then
classify_non_type_nameis called, which detects it's a value, but the function also has logic that says "this IS a value, return error"
The fix should be in
resolve_type_nameto check if the qualified name refers to a type, and if not, fall back to the prelude.Let me look at where the
DefinitionBodyis for both:Assistant
Now let me understand the structure better. When the discordgo generated file has
pub const Unknown: Locale = "", that becomes aValue { .. }body in the module's definitions. The prelude'sUnknownis aTypeAlias(or other type body).Let me think about the proper fix. The check should be:
In
resolve_type_name, when a lookup finds a definition, we should check that the definition's body is a type-like body. If not, we should fall through to the prelude.Actually, looking at this more carefully, I think the fix should be applied in the
resolve_type_with_arityfunction. It already has logic to fall back to the prelude if arity doesn't match. We can extend this: if the lookup finds a non-type definition, fall back to the prelude.Let me look at how the prelude gets registered:
Assistant
So the prelude is registered as an unprefixed module. So when looking up
Unknown, it should fall through both the module's own definitions and check imports. The issue is the module's own definitions take precedence over the unprefixed imports.Now let me understand: if
discordgo.Unknownis aValuebody, thenlookup_qualified_namewill find it in the current module's definitions. Thenresolve_type_namereturns this. Thenresolve_type_with_aritychecks if the arity matches; if so, returns; otherwise falls back to prelude.The bug:
discordgo.Unknownhas arity 0 (it's just a const), so it appears to match what the prelude'sUnknownwould also have. So we never fall back to the prelude.The fix: in
resolve_type_name, after finding a definition, check if it's actually a type. If not, fall through to try the prelude.Let me look at how to check if something is a type:
Assistant
Now let me look at what tests are already there for this scenario:
Assistant
Interesting! This is a similar check that prevents
anyandcomparablefrom being shadowed in user-declared types. Let me look at what does for the prelude/predeclared:Assistant
Let me check the bindgen file structure:
Assistant
Now let me look at how I might write a reproducer:
Assistant
Now let me look at the existing tests for
value_in_type_position:Assistant
Let me look at one of these tests:
Assistant
Now I understand the test setup. Let me think about the proper fix now.
Let me re-look at the resolve_type_with_arity function:
Assistant
Now let me think about this. The flow is:
resolve_type_with_arity("Unknown", 0)is called forVarArgs<Unknown>resolve_type_name("Unknown")returns(discordgo.Unknown, ty)sinceUnknownis in the module's definitions- The arity matches, so it returns
(discordgo.Unknown, ty) classify_non_type_namedetects this is a Value definition, errors out
The fix needs to either:
- Make
resolve_type_nameskip values that are not types - so the prelude'sUnknownis used instead - Make
resolve_type_with_arityfall back to the prelude when the found definition is not a type - Make
lookup_qualified_namemore aware of what's a type vs value
The cleanest approach is to modify
resolve_type_nameto detect when a name resolves to a value (not a type) and returnNoneso that the caller can fall back to the prelude. However, this might break other lookup cases (for the value usage we still need to find discordgo.Unknown).Actually, the cleanest approach is to make a separate
resolve_type_only_namefunction that skips values, and use it inresolve_type_with_arity.Let me check how
resolve_type_nameis used elsewhere:Assistant
Let me check the use at convert.rs:68:
Assistant
Now I want to understand the bigger picture. Let me check where
Type::NominalIDs come from and how they end up in the user-visible AST:Assistant
Now this confirms the issue. The Go code emitter is mapping
Unknowntoany(Go's type), but if the qualified name isdiscordgo.Unknown, it will treat it as a Go-discordgo type instead.Let me run a quick test to verify the issue. First, let me see how the build system works:
Assistant
Now let me create a temporary test to actually reproduce the issue:
Assistant
Now let me look at how
infer_with_go_typedefsworks to create a test:Assistant
Now let me create a test script to reproduce the issue:
Assistant
Now let me create a test reproducer:
Assistant
Let me focus on understanding the actual code path. Let me look at how the existing tests check the discordgo-like scenario:
Assistant
Now I have a clear picture. Let me write a simple reproduction first:
Assistant
Now let me set up a simpler way to reproduce the issue using cargo test. I'll add a reproducer test temporarily:
Assistant
Wait, the actual issue is in the BINDGEN output file - the function signatures have
Unknownas a TYPE. Let me re-read the issue:Assistant
Let me first manually run the test by patching the test file:
Assistant
I have reproduced the error. Now let me think about the fix:
- The fix should be in
resolve_type_name(and/orresolve_type_with_arity) in/lisette/crates/semantics/src/checker/registration/convert.rsormod.rs.
Let me look at what the right approach is. When the user writes
discordgo.Unknownin a type position:resolve_type_nameis called fordiscordgo.Unknownlookup_qualified_nameis called fordiscordgo.Unknown- That checks prefix
discordgo, module_id is the discordgo module - It checks the module for
Unknownand finds the const value - The issue is that
discordgo.Unknownis a value, not a type
Looking back at the code:
pub(crate) fn lookup_qualified_name( &self, store: &Store, type_name: &str, ) -> Option<EcoString> { if let Some((prefix, simple_name)) = type_name.split_once('.') // <-- HERE: Type is `discordgo.Unknown` so prefix = discordgo && 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()); } ...This is the path where the qualified name
discordgo.Unknownis fully resolved using the prefix. In this case,lookup_qualified_namereturnsdiscordgo.Unknown(the const), andresolve_type_namereturns this as a type. That's clearly incorrect.So the fix should be: when used in a TYPE position, we should reject value definitions and try other resolutions.
Looking at it more carefully, there are two cases:
discordgo.Unknown- the user explicitly qualified with the package prefixUnknown- the user wrote justUnknown, and lookup falls back to imports
For case 1, the user explicitly says "I want discordgo's Unknown". But discordgo's Unknown IS a value, so it can't be used as a type. The error message could be more helpful.
But hold on - looking at the actual reported error, the issue is in the generated bindgen file itself -
Unknownis emitted in type position WITHOUT adiscordgo.prefix. The bindgen generates this:pub var Logger: fn(int, int, string, VarArgs<Unknown>) -> ()So the qualified name lookup falls through to imports.
Let me trace this again:
- When parsing
VarArgs<Unknown>in the discordgo.d.lis file, the module being analyzed IS discordgo. lookup_qualified_name(store, "Unknown"):- No
.inUnknown, so first check skipped module.definitions.contains_key("discordgo.Unknown")- YES (it's a const)- Returns
discordgo.Unknown
- No
resolve_type_namereturns(discordgo.Unknown, ty)- The arity matches, so
resolve_type_with_arityreturns(discordgo.Unknown, ty) classify_non_type_namechecks the definition body and finds it's a Value, so errors out
So the issue is clear. Now the fix:
The most principled fix would be in
lookup_qualified_name- skip non-type definitions when they're in the prelude. Or, inresolve_type_name, check if the definition is a type before returning it.Actually, I think the cleanest fix is to modify
resolve_type_nameto ONLY return type definitions. If we find a value definition, we should return None, so the caller can fall back to other resolutions (like the prelude). For the explicitdiscordgo.Unknowncase (which is a value), the error should still be raised but the error message could be more informative.Let me look at the
classify_non_type_nameto understand what helpful messages we can give:The
classify_non_type_namecurrently:- Checks if the qualified name refers to a value definition
- If yes, returns kind + helpful message
- If the qualified name is the same as the type's id (self-reference), returns None (no error)
Actually, looking at this more carefully, I think the issue says the bindgen should disambiguate, not change the resolver. Let me re-read:
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.
So the issue says either option is acceptable. The simplest is to make the bindgen avoid the name clash by renaming the constant when it shadows
Unknown. But this might be a problem because the constant could be called anything fromUnknowntoFoo. Actually, it's specifically theUnknownname in this case.The cleanest approach would be to:
- In the bindgen, detect when a constant shadow's the prelude's
Unknown(since that's the only one in the prelude that has the same semantics asany), and either rename it or rename the type usage. - Or: change the resolver to prefer prelude
Unknownover module-localUnknownwhen used in type position.
Let me think about this. The bindgen generates
Unknownas a const. We could:- Either rename the const (e.g.,
Unknown_<value>) - Or use a qualified name for the const
Looking at bindgen output for
discordgo.Unknownconst:- The fix should be in
Assistant
Looking at how the bindgen creates a
Localenewtype:Assistant
Now I have a clear picture. Let me look at what an "Unknown" const is generated like. Let me check the bindgen for discordgo pattern - i.e. when Go defines a const named
Unknownof an enum type:Assistant
Now let me think about the proper fix. The approach should be:
- Approach A: Modify the bindgen to detect when a const named
Unknownis emitted and rename it (e.g.,Unknown_orUnknown_Locale). - Approach B: Modify the resolver to handle this case - when looking up
Unknownin type position, prefer the prelude if the module-local one is a value. - Approach C: A combination - bindgen should rename the const AND the resolver should handle the type-precedence.
Let me focus on the resolver fix since it's the most general. Looking at how Lisette resolves
Unknownin type position:In
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)); } // falls through to prelude for arity mismatch return Some((qname, ty)); } self.resolve_type_from_prelude(store, type_name)The issue is: when
discordgo.Unknownis found, it's a value not a type. We should fall through to the prelude.Looking at the code flow more carefully:
resolve_type_with_arityis called forUnknown(in discordgo.d.lis parsing)resolve_type_name("Unknown")returns(discordgo.Unknown, ty)(the const value's type)- The arity matches (both
Unknownconst andUnknowntype have 0 arity), so it returns the discordgo one - Later,
classify_non_type_namecatches this and errors
The cleanest fix is in
resolve_type_name: if the resolved definition is a Value (not a Type), we should treat it as if we didn't find the type. Then the caller will fall back to the prelude. But for explicit qualification likediscordgo.Unknown, we still want to surface the error.Let me think about this more carefully:
For
discordgo.Unknownin type position:- User explicitly says "use discordgo's Unknown as a type"
- discordgo's Unknown is a value (a
Locale) - This SHOULD be an error: cannot use a value as a type
- Currently the error is "Value in type position"
For
Unknown(in discordgo.d.lis context):- The user (bindgen) wrote
Unknownthinking it's the built-in - The module has a const
Unknownshadowing the built-in - We want to use the built-in
Unknowninstead
So the fix should be: in
resolve_type_name, if the unqualified name is in the current module's definitions but the definition is a Value (not a Type), then skip it and look in the imports (prelude first, then other imports).Let me look at how this can be implemented cleanly:
- Approach A: Modify the bindgen to detect when a const named
Assistant
Let me look at the conversion flow again:
Assistant
I see. Now let me think about the cleanest fix.
Actually, I think the right approach is to modify
lookup_qualified_nameandresolve_type_nameto handle this case properly. When looking upUnknownand the local definition is a value (not a type), we should fall through.But there's a subtlety:
lookup_qualified_nameis used for VALUES too, not just types. So we can't change it directly.Let me look at all callers of lookup_qualified_name to see how it's used:
Assistant
The cleanest place to put the fix is in
resolve_type_name(andresolve_type_with_arity). Modify them to ignore Value definitions.Let me look at it more carefully:
Assistant
OK. Now let me check what types of definition bodies we have. I'll think about this:
For each definition body:
TypeAlias: a type alias, this is a typeEnum: an enum, this is a typeStruct: a struct, this is a typeInterface: an interface, this is a typeValue: a value (variable, constant, function), NOT a type
So in
resolve_type_name, we should check that the resolved definition is one ofTypeAlias,Enum,Struct, orInterface. If it's aValue, we should returnNoneso the caller can fall back to the prelude.Now let's think about side effects:
resolve_type_name(store, "Unit")is called to check ifUnitis a user-defined type. If we return None for Value definitions, this still works correctly.- Other places use
lookup_qualified_namedirectly and don't care about type vs value distinction.
Let me think about edge cases:
discordgo.Unknown- user explicitly uses qualified name. This is a Value. The error should still be raised.- Current behavior: lookup returns
discordgo.Unknown, classify detects Value, error raised. ✓ - New behavior: lookup returns None (since it's not a type), then
resolve_type_with_arityfalls back to prelude which doesn't havediscordgo.Unknowneither... sotype_not_founderror.
- Current behavior: lookup returns
Hmm, this is not what we want. For the qualified case, we should still detect that the user was trying to use discordgo.Unknown as a type and give a clear error.
Wait, looking again at
resolve_type_name. The qualified name path only matches iflookup_qualified_namefinds it. The fix atresolve_type_namewould be:- If the resolved body is a Value, return None
- The caller (
resolve_type_with_arity) then tries the prelude - If the prelude doesn't have it, error: "type not found"
But we want different errors:
- For
discordgo.Unknown(qualified, but value): "discordgo.Unknown is a value, not a type" - For
Unknown(unqualified, but value shadows prelude): should use the prelude's Unknown
So the fix should be more nuanced. Let me think:
For an unqualified name
Unknown:- Module has a Value
Unknown: skip it, fall back to prelude - Prelude has Type
Unknown: use it
For a qualified name
discordgo.Unknown:- discordgo has a Value
Unknown: this is an error ("value in type position") - No fallback needed - the user specified this exact name
Let me look at
lookup_qualified_nameagain:if let Some((prefix, simple_name)) = type_name.split_once('.') // Qualified name? && 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()); } let module = store.get_module(&self.cursor.module_id)?; let qualified_name = Symbol::from_parts(&module.id, type_name); // Check current module if module.definitions.contains_key(qualified_name.as_str()) { return Some(qualified_name.as_eco().clone()); } for imported_module_id in &self.imports.unprefixed_imports { // Check unprefixed imports ... }So for an unqualified name
Unknownin the discordgo module:- Goes to "Check current module" → finds
discordgo.Unknown - Returns
discordgo.Unknown
For a qualified name
discordgo.Unknown:- Goes to "Qualified name" → finds
discordgo.Unknown - Returns
discordgo.Unknown
The cleanest fix: modify
lookup_qualified_name's "Check current module" branch to skip Value definitions (i.e., continue to the next step). But wait - we WANT to find Value definitions for value positions, so we can't just skip them entirely.OK, the cleanest approach is:
- Add a variant of
lookup_qualified_namethat only returns type-like definitions, OR - Add a flag parameter to filter the result, OR
- Modify
resolve_type_nameto check the body type and fall back if it's a value.
I think (3) is the simplest. The challenge is: how do we make sure that the qualified case still gets an error.
The flow is:
resolve_type_with_arity("discordgo.Unknown", 0)(the qualified case)resolve_type_name("discordgo.Unknown")finds the qualified name- We want this to return
Noneso we can show the "value_in_type_position" diagnostic - Then the caller falls back to the prelude
- The prelude doesn't have
discordgo.Unknown - So the caller returns None too
- The caller (
Annotation::Constructor) shows "type_not_found" error
For the qualified case, the current behavior:
resolve_type_with_arity("discordgo.Unknown", 0)resolve_type_name("discordgo.Unknown")finds the qualified name- Returns
(discordgo.Unknown, ty) - Caller uses this name
classify_non_type_namedetects Value → shows "value_in_type_position" error ✓
If I modify
resolve_type_nameto return None for Value definitions:resolve_type_with_arity("discordgo.Unknown", 0)resolve_type_name("discordgo.Unknown")returns None (because it's a Value)- Falls back to
resolve_type_from_prelude("discordgo.Unknown")→ returns None resolve_type_with_arityreturns None- Annotation shows "type_not_found" error
- The user wouldn't know that
discordgo.Unknownexists, just that the type was not found
So we'd lose information. To preserve it, we'd need to track that we explicitly found a Value but it's not a type.
Actually, I think the right fix should be more nuanced:
Plan:
- In
resolve_type_with_arity, when we find a definition viaresolve_type_name, check if it's a Value (not a type) - If it's a Value:
- If the user used qualified syntax (
discordgo.Unknown): keep the current "value in type position" error path - If the user used unqualified syntax (
Unknownin discordgo.d.lis context): treat as if no type was found, fall back to prelude
- If the user used qualified syntax (
Let me look at the issue again. The reported error is from the discordgo.d.lis file itself, where the bindgen emits
VarArgs<Unknown>. So we just need to handle the UNQUALIFIED case.Actually, after thinking more, the cleanest fix is in
lookup_qualified_namefor the "Check current module" branch. When looking up the unqualified name in the current module, if we find a Value but not a type, we should continue to the unprefixed imports check (which includes the prelude).But for
discordgo.Unknown(explicitly qualified), we don't go through this branch.Let me check this approach:
For unqualified
Unknownin discordgo.d.lis:lookup_qualified_name("Unknown")- No
.in name, so skip the qualified check - "Check current module": finds
discordgo.Unknown(Value). Skip and continue. - "Check unprefixed imports": finds
prelude.Unknown(Type). Return this.
For qualified
discordgo.Unknown(which shouldn't really be valid but anyway):lookup_qualified_name("discordgo.Unknown")- Has
., look up "discordgo" prefix → discordgo module - Find
Unknownin discordgo module → Value - Return
discordgo.Unknown - classify_non_type_name detects Value, error raised ✓
This approach works! Let me implement it.
Actually, wait. Let me re-read
lookup_qualified_nameto make sure I understand the semantics. The functionlookup_qualified_namereturns the qualified name if the simple name can be found. Currently: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()); }It uses
module.definitions.contains_key(...). This checks if the name exists at all (regardless of whether it's a type or value).If we change this to skip Value definitions, we need to be careful:
- For VALUE resolution (like
let x = Unknown), we still want to find discordgo's Unknown const. - For TYPE resolution (like
Slice<Unknown>), we want to skip Value and fall through.
Wait, value resolution might use a different code path. Let me check.
Assistant
OK so it's used both for value and type resolution. So I shouldn't change
lookup_qualified_namedirectly.Let me think differently. The change should be local to the
resolve_type_with_arityfunction. Specifically: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)); } // ... fallback to prelude } self.resolve_type_from_prelude(store, type_name) }The fix would be:
resolve_type_nameshould returnNoneif the definition is a Value (not a type). The caller can then fall back to the prelude automatically.But the question is: how does this interact with the qualified case
discordgo.Unknown?Let's think:
- For qualified
discordgo.Unknown(value): the current behavior gives "value_in_type_position" error. With my change, it gives "type_not_found" error - WORSE. - For unqualified
Unknown(in discordgo.d.lis): the current behavior gives "value_in_type_position" error. With my change, it correctly resolves toprelude.Unknown. - GOOD.
So we need to differentiate. Let me think about the right approach.
OK, here's a clean approach:
- Modify
resolve_type_with_arityto check if the resolved type is actually a type definition body. If not, treat as arity mismatch and fall back to prelude. - The current
classify_non_type_namewill only fire when the qualified name is explicitly used (likediscordgo.Unknown), not for unqualifiedUnknown.
Let me trace through:
discordgo.Unknown(qualified, discordgo is the local module):lookup_qualified_nameis called withdiscordgo.Unknown- Falls into the qualified branch (not the "current module" branch)
- Finds
discordgo.Unknownand returns it resolve_type_namereturns the qualified nameresolve_type_with_aritychecks arity - matches (both 0). But we want this to be classified as not-a-type.- With my change,
resolve_type_with_aritywould also need to check if the body is a Value. - If it's a Value, fall through to the prelude. Hmm but the prelude doesn't have
discordgo.Unknown. So we return None. - Then the caller (Annotation::Constructor) shows "type_not_found" error.
- This is WORSE.
Wait, looking at the code more carefully:
pub(super) fn resolve_type_with_arity( ... ) -> Option<(String, Type)> { ... if let Some((qname, ty)) = self.resolve_type_name(store, type_name) { if arity_of(&ty) == expected_arity { return Some((qname, ty)); } // fallback for arity mismatch 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)); } // Found in current scope, return it (arity mismatch) return Some((qname, ty)); } self.resolve_type_from_prelude(store, type_name) }So we ONLY fall back to prelude if there's no
.in the type name. The reasoning: qualified names are explicit, so we should respect them.So for
discordgo.Unknown(qualified), if the arity matches, we don't try the prelude. This is the case wherediscordgo.Unknownis a Value but used as a type - we still want to raise the "value_in_type_position" error.For
Unknown(unqualified in discordgo.d.lis), if the arity matches, we use the current module's Unknown (which is a Value), thenclassify_non_type_nameraises the error.So the fix should be: even though arity matches, if the resolved name is a Value, AND the name is unqualified (
!type_name.contains('.')), fall back to prelude. The qualified case can still go throughclassify_non_type_name.Let me look at the source once more:
- For qualified
Assistant
Good. So the simplest fix would be to add the "is a Value" check:
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 the resolved name refers to a value (not a type), only fall // back to the prelude for unqualified names. Qualified names // like `pkg.Foo` are explicit user intent — surface as // "value_in_type_position" downstream. let is_value = store .get_definition(&qname) .is_some_and(|d| matches!(d.body, DefinitionBody::Value { .. })); if arity_of(&ty) == expected_arity && !is_value { 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) }Wait, but if I do this, then for
discordgo.Unknown(qualified), thearity_of(&ty) == expected_arity && !is_valuecheck fails, and we fall to theif !type_name.contains('.')- but it contains., so we skip. So we return the qualified discordgo.Unknown. Then classify_non_type_name would catch this and raise the error. ✓For
Unknownin discordgo.d.lis (unqualified): thearity_of(&ty) == expected_arity && !is_valuecheck fails because of the value check. We try prelude - findprelude.Unknown. ✓But wait, there's a case: what if
Unknownis also an enum variant? Actually enum variants are inside the enum, but when there's a const value calledUnknownin the local module, it should not be reached. The currentclassify_non_type_nameprovides a helpful error for various cases (function, value, enum variant), so let me make sure we preserve that behavior for the qualified case.Actually, I realize there's still an issue. Looking at:
if let Some((qname, ty)) = self.resolve_type_name(store, type_name) { if arity_of(&ty) == expected_arity { return Some((qname, ty)); } ... }For the qualified case
discordgo.Unknown:- Resolve type returns
(discordgo.Unknown, ty)- ty is the Locale type that the const has arity_of(ty) == 0 == expected_arityis true- We return the result, then classify_non_type_name catches it. ✓
With my proposed change for the unqualified case
Unknownin discordgo.d.lis:- Resolve type returns
(discordgo.Unknown, ty)- ty is the Locale type arity_of(ty) == 0 == expected_arityis true BUT is_value is true → condition fails- We try prelude: finds
prelude.Unknown - Return that ✓
For the qualified case
discordgo.Unknown:- Resolve type returns
(discordgo.Unknown, ty) - arity matches but is_value is true → condition fails
- We try
!type_name.contains('.')- false (has dot), skip - Return discordgo.Unknown anyway
- classify_non_type_name catches it ✓
Now let me also check the binding generator side. Should the bindgen also handle this? Looking at the issue, the expected behavior says EITHER is acceptable. Let me handle both:
- Fix the resolver (more general, handles other cases)
- Maybe also do something in the bindgen
Actually, the bindgen fix would be to RENAME the
Unknownconst so it doesn't shadow the prelude. Let me think about the tradeoffs:- Pros: Bindgen rename is more proactive - it prevents the conflict from happening in the generated code
- Cons: User-facing names change
Looking at how this is handled in the bindgen right now (for
anyandcomparable), thepredeclared_shadowingcheck rejects user declarations with those names. Similarly, the bindgen should not generate declarations with names likeUnknownthat shadow the prelude.Actually, let me look more carefully: what if the resolver fix is enough? The "value_in_type_position" error would happen for any undefined value-like names, but for
Unknown(unqualified) we want it to resolve cleanly.Let me go with the resolver fix, since it's more general. Let's also look at the bindgen to see if it has an existing mechanism for renames:
- Resolve type returns
Assistant
No rename mechanism. Let me think about whether the resolver fix is sufficient.
Actually, looking at the issue more carefully, the recommended fix in the expected behavior is:
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.
Let me think about the resolver fix. The fix would essentially be: in
resolve_type_with_arity, if the resolved name is in the current module's definitions but is a Value, AND the type_name is unqualified, fall through to the prelude.Let me also think about the case where someone has a type in the same module with a shadowing const:
module foo { pub const Unknown: int = 0 pub type Unknown = ... // wait, you can't have two things with the same name }Actually, you can't have both a const and a type with the same name in Lisette (different from Go). So inside a module,
Unknownis either a const OR a type, not both.OK so the question is: when a module has
Unknownas a const, the prelude'sUnknownshould be used in type positions.Wait, but what if the user wants
foo.Unknownas a const? They'd writelet _ = Unknown(unqualified). That should still work - find foo.Unknown.Actually, the fix should be in
resolve_type_name(orresolve_type_with_arity). Specifically, when used for type resolution, the function should only return type-like definitions. Values should be ignored (and fall through to prelude).But for value resolution (like
let x = Unknown), the lookup still needs to find foo.Unknown. So we can't changelookup_qualified_name.The cleanest approach is to:
- Modify
resolve_type_nameto check the body type and ignore Value bodies - The caller of
resolve_type_name(which isresolve_type_with_arity) will then fall back to the prelude
But the qualified case (like
discordgo.Unknownin type position) would also be affected. We'd lose the "value in type position" diagnostic. Let me think...Actually wait, I miscounted. Let me re-read the lookup_qualified_name:
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()); // <-- qualified case returns here } 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()); // <-- unqualified case in current module returns here }For the qualified case
discordgo.Unknown:- prefix="discordgo", simple_name="Unknown"
- finds discordgo module, finds Unknown
- Returns
discordgo.Unknown
For the unqualified case in discordgo.d.lis where
Unknownis in discordgo module's definitions:- Goes to "Check current module" branch
- Returns
discordgo.Unknown
So in both cases, the same
discordgo.Unknownis returned. Now if I modifyresolve_type_nameto ignore Value bodies:- For
discordgo.Unknown(qualified): returns None, falls through. User loses the "value in type position" error. - For
Unknown(unqualified in discordgo.d.lis): returns None, falls through to prelude, findsprelude.Unknown. ✓
To preserve the qualified case error, I should change lookup_qualified_name to skip Value definitions ONLY in the "Check current module" branch (not the qualified branch). Then:
- For qualified case: still finds discordgo.Unknown (Value), still triggers classify_non_type_name error
- For unqualified case: skips discordgo.Unknown (Value), falls through to prelude imports
Let me implement this approach. Actually wait, there are other paths through
lookup_qualified_name:- "qualified with prefix and module" branch
- "Check current module" branch
- "Check unprefixed imports" (including prelude) branch
For the unqualified case, the flow is:
- "Check current module" - finds discordgo.Unknown (Value)
- With my fix: skip (Value, not type), continue to step 3
- "Check unprefixed imports" - finds prelude.Unknown, return it ✓
This is what we want. Let me modify the function.
Actually wait, let me think about this differently. The issue is specifically about TYPE positions. So the fix should be TYPE-specific. Modifying
lookup_qualified_namemakes it module-wide applicable (both for type and value resolution), which might break other things.Let me look at how value resolution works. When the user does
let x = Unknown, how does it look up?Looking at primitives.rs line 244:
let qualified: Option<EcoString> = if binding_id.is_none() { self.lookup_qualified_name(store, &value) }So in value position,
lookup_qualified_nameis also called. This is howUnknown(the const value) is resolved.If I modify
lookup_qualified_nameto skip Value definitions in the "current module" branch, then this code path would also be affected. The constUnknownwouldn't be found in value position either!So I can't modify
lookup_qualified_nameglobally. I need a type-specific version.Let me think... One option:
- Add a parameter to
lookup_qualified_name(e.g.,accept_types_only: bool) - Use this in
resolve_type_name
But that changes the function's signature. Let me check if that's OK:
- Modify
Assistant
OK it's used as
pub(crate). We can change the signature.Actually, the simpler approach is to just check inside
resolve_type_namewhether the resolved name is a type. If not, returnNone(so the caller falls back). But this affects the qualified case.Actually, here's another approach: do the fix at the level of
resolve_type_with_arity. After getting theqnamefromresolve_type_name, check if the definition is a Value. If it is, try the prelude and only use the qualified result if the prelude doesn't have it.Let me revise my approach:
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, }; let resolved = self.resolve_type_name(store, type_name); // If the resolved name refers to a value (const/var/function), only use it as a type // for explicitly qualified names like `pkg.Name`. For unqualified names, fall back // to the prelude so built-in types like `Unknown` are not shadowed by Go-package // constants of the same name (e.g. discordgo's `Unknown` Locale). let qname_is_value = resolved.as_ref().is_some_and(|(qname, _)| { store.get_definition(qname).is_some_and(|d| matches!(d.body, DefinitionBody::Value { .. })) }); if let Some((qname, ty)) = resolved { if arity_of(&ty) == expected_arity { if qname_is_value && !type_name.contains('.') { // Skip the value, try the prelude if let Some((pname, pty)) = self.resolve_type_from_prelude(store, type_name) && arity_of(&pty) == expected_arity { return Some((pname, pty)); } // Fall through to the value path below } else { return Some((qname, ty)); } } // Arity mismatch fallback 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) }This is cleaner. Let me re-verify the logic:
For unqualified
Unknownin discordgo.d.lis:resolve_type_namereturns(discordgo.Unknown, ty)qname_is_valueis truearity_of(ty) == 0 == expected_arity, but value AND no.→ go into the prelude branch- Find
prelude.Unknown, return it ✓
For qualified
discordgo.Unknown:resolve_type_namereturns(discordgo.Unknown, ty)qname_is_valueis true- arity matches, has
.→ go into the else branch → return discordgo.Unknown classify_non_type_namecatches it → error ✓
For unqualified
Unit(in user code):resolve_type_namereturns(user.Unit, ty)(if user has Unit) - it's a Valueqname_is_valueis true, no.→ go into the prelude branch- Prelude doesn't have
Unitunless user defined it (it doesn't by default) - Return None →
type_not_founderror
Wait, that's wrong!
Unitis a special case. The code path actually skips this:if type_name == "Unit" && params.is_empty() && self.resolve_type_name(store, "Unit").is_none() { return Type::unit(); }This says: "if Unit is not found as a type, use the internal unit type". But if we return None for Value definitions, this still works - Unit is not in the prelude (as a value).
Actually, looking at the prelude:
Assistant
OK so
Unitis a special internal type. The checkresolve_type_name(store, "Unit").is_none()is for when the user has definedUnitin the current module. If yes, use it; otherwise use the internal unit type.With my fix: if the user defines
Unitas a const, the existing behavior would be "use it (then classify_non_type_name errors)". With my change: also falls through to prelude. But the prelude doesn't have Unit (it's special internal). So we'd return None, and theis_none()check works.So the fix is OK for Unit.
Wait, what about
bool,int, etc.? These are also in the prelude. Let me check whatresolve_type_namereturns forint:Assistant
OK so the prelude has them as TypeAlias. So
resolve_type_name(store, "int")would findprelude.int(Type) and not return a Value.Now what about my proposed change for the case where the local module has
pub const int: int = 5? Edge case, but let me check the current behavior and what it'd be with my change:- Current:
resolve_type_name(store, "int")→(my_module.int, ty)(int const). Arity matches. Return.classify_non_type_nameerrors. - My change:
resolve_type_name(store, "int")→(my_module.int, ty). is_value is true, no., no prelude match (prelude.int is a Type, not Value, but ourvalue_in_type_positioncheck...
Wait, I need to recheck.
resolve_type_from_preludeonly finds the prelude. Forint:prelude.intexists (Type)resolve_type_from_prelude(store, "int")returns(prelude.int, ty)- With my change, we'd find this in the prelude branch
- Return
prelude.int✓
So the fix works for shadowing of
int,bool, etc.OK let me also think about another case: what if the local module has BOTH a const
Unknownand a typeUnknown? Well, Lisette doesn't allow that, but Go does. Let me think about how the bindgen handles this... actually I think it can't because Lisette types and consts share a namespace. So this isn't an issue.Let me implement the fix now.
But wait, before I implement - let me also check that my understanding of
resolve_type_with_arityis correct by looking at the prelude_shadowing.rs and predeclared_shadowing.rs:- Current:
Assistant
So there's already a check that prevents user declarations of
anyandcomparable. Hmm, but that's only for USER-written code, not for bindgen-generated.d.lisfiles.Let me check the user's reproduction. The discordgo package is imported by the user. The bindgen-generated
discordgo.d.lisfile would have apub const Unknown: Locale = "". But the user is not declaring this in their code - the bindgen does it.The bindgen generates
.d.lisfiles for Go packages. So my fix needs to handle the case where bindgen-emitted code has a const with the same name as a prelude type.Let me also see how the prelude_shadowing.rs handles this:
Assistant
So there are warnings about shadowing prelude types. But this is for USER code. It only checks top-level definitions. Constants wouldn't trigger this.
Looking at this issue from the bindgen perspective: the bindgen should generate code that doesn't shadow prelude types. But the actual fix here is in the resolver, which is more general.
Actually, looking more carefully at the
prelude_shadowing.rs, it only checks top-levelExpression::Enum,Struct,TypeAlias,Interface. It doesn't checkconstdeclarations. And it runs ontyped_ast(post-inference). So it doesn't really help us here.OK let me implement the resolver fix. Let me look at one more thing - the
resolve_type_namefor non-current module paths:Assistant
There's an
is_type_definitionmethod! Let me use that.Now let me make the implementation:
Assistant
Now let me implement my fix. First let me look at
resolve_type_with_arityandresolve_type_namemore carefully:Assistant
Good, DefinitionBody is already imported. Now let me implement the fix. I'll modify
resolve_type_with_arity:Assistant
Let me apply the fix:
Assistant
Now let me look at this carefully. The
classify_non_type_namefunction - if I makeresolve_type_with_arityskip Value definitions for unqualified names, this function will not be called forUnknown(unqualified in discordgo.d.lis). But it WILL still be called fordiscordgo.Unknown(qualified).Wait, I think there's still an issue with my proposed approach. Let me think about how qualified name resolution works:
For
discordgo.Unknown(qualified):lookup_qualified_name(store, "discordgo.Unknown"):type_name.split_once('.')→ ("discordgo", "Unknown")self.imports.prefix_to_module.get("discordgo")→ Some("discordgo module id")store.get_module("discordgo module id")→ Some(discordgo module)self.resolve_in_imported_module(discordgo, "Unknown")→ returns the qualified namediscordgo.Unknown- Returns
discordgo.Unknown
OK so the qualified name lookup doesn't go through the "current module" branch. It goes through the qualified branch.
For
Unknown(unqualified) in the discordgo.d.lis file:lookup_qualified_name(store, "Unknown"):- No
.in name, skip qualified branch store.get_module(self.cursor.module_id)→ discordgo modulequalified_name = Symbol::from_parts(discordgo, "Unknown")= "discordgo.Unknown"discordgo.definitions.contains_key("discordgo.Unknown")→ YES- Returns
discordgo.Unknown
- No
So the difference is: in the qualified case, the user EXPLICITLY says "I want discordgo's Unknown"; in the unqualified case, the user just writes
Unknownand the module-local one wins.With my proposed fix in
resolve_type_with_arity:- Qualified case: my fix wouldn't skip (because
type_name.contains('.')is true), so it returns(discordgo.Unknown, ty). Thenclassify_non_type_namecatches it. ✓ - Unqualified case: my fix skips (because
qname_is_valueis true and no.), so it falls to prelude. Returns(prelude.Unknown, ty). ✓
Let me make the implementation:
Assistant
Now let me verify the change:
Assistant
Good. Now let me run the test to verify:
Assistant
Hmm, still failing. Let me look at the actual flow again. The error is on the source code, not on
discordgo.Unknown(which uses a fully qualified prefix). Wait, let me reread:Assistant
I see. The test has
discordgo.Unknownwhich is a qualified name. The user's repro case in the issue is about the discordgo.d.lis file itself, whereUnknown(UNqualified) is used in type positions likeVarArgs<Unknown>.Let me update the test to mimic that better:
Assistant
The test is now passing. Now let me think about edge cases:
- Qualified case
discordgo.Unknown: Should still raise "value in type position" error. - Unqualified case
Unknownin discordgo.d.lis: Should resolve to prelude's Unknown. ✓ - What if discordgo has a type
Unknown(not possible per Lisette, but check anyway). - What about other types like
int,bool,stringbeing shadowed by values.
Let me test the qualified case to make sure the error is still raised:
- Qualified case
Assistant
There's no public
code_namemethod. Let me check assert_infer_code:Assistant
OK there's
code_str(). Let me fix my test:Assistant
Both tests pass. Now let me think about more edge cases:
-
What if discordgo has both a const
Unknownand a different typeUnknown_renamedthat's used asUnknownin the typedef? - Not a problem, const != type. -
What if a value shadows a prelude type with arity 1, like an enum? - Need to check.
-
What about the user's
discordgo.Unknownvalue being valid in VALUE position? - Should still work since we didn't change the value resolution.
Let me test the value resolution:
-
Assistant
All three tests pass. Now let me run the entire test suite to make sure I didn't break anything:
Assistant
1576 tests failed! Let me check what's broken:
Assistant
1576 failures! Let me look at one specific failure:
Assistant
Wait, this test failure is unrelated to my change! It's just a formatting issue. Let me check if this test was failing before my change:
Assistant
Good - this test was already failing before my change. Let me apply my changes back:
Assistant
Let me check what tests pass without my changes vs. with. Let me run the test on master first to see the baseline:
Assistant
OK so 1576 tests are already failing on master. So those failures are unrelated to my changes. Let me restore my changes:
Assistant
The number of failures is the SAME (1576). My changes don't introduce any test regressions! And actually passed 3572 → 3575 tests (3 more, because my 3 new tests are passing).
Now let me also look more carefully at the bindgen side. The issue says:
the binding generator should qualify/disambiguate imported names that shadow built-in types
Actually, looking at this more carefully, I think there's a problem with my fix that's beyond just the resolver. Let me think...
When the bindgen generates discordgo.d.lis with
pub const Unknown: Locale = "", this is valid Go code. In Lisette, the constUnknownwill shadow the prelude'sUnknowntype WHEN USED IN THAT MODULE. But user code that imports discordgo and usesdiscordgo.Unknownas a value should still get the const.But wait - what if another module's .d.lis is processed and uses
discordgo.Unknown(qualified value reference)? Let me think... well, this works throughdot_accessor other value-position lookup, not type resolution. So it's fine.Now let me also think about the bindgen - should I also rename the const in bindgen output? Let me look at the issue again:
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.
The "or" suggests either approach is fine. My resolver fix should be sufficient. But let me also verify by trying to think about other cases:
- What if the user writes their own code with
Slice<Unknown>in a module that haspub const Unknown: ...? My fix should handle this. - What if discordgo's typedef has
pub fn F(x: Unknown)(a function withUnknownparameter)? My fix handles this. - What about types like
Slice,Map,Option, etc.? Those don't have the same name conflict.
Let me also check that the resolver change handles the case where
Unknownis in a const with a different signature:Wait, I need to also think about which prelude types might be shadowed. The prelude has:
int,int8, etc. - primitive typesbool,string, etc.rune,byte, etc.Unknown- the special oneOption,Result,Range, etc.assert_type,panic- functions
If a Go package has a const
int(likeconst int MyInt = 5), this would shadow the prelude'sinttype in type position. With my fix, this would also work correctly.Let me test this:
- What if the user writes their own code with
Assistant
All 4 cases pass. Let me also test edge cases:
- Function reference (where
unknowncould be a function name) - Var reference (where
unknowncould be a var name) - Multiple levels of shadowing
- Function reference (where
Assistant
All cases pass. Now let me clean up my test file (since it's a temporary file for testing - we don't want to add new tests to the repository):
Assistant
Let me restore the mod.rs:
Assistant
Now let me check the current state:
Assistant
There are a lot of
.snap.newfiles. These are unrelated to my changes - let me check what they are:Assistant
This is a pre-existing test failure unrelated to my changes - it's about formatting. Let me clean up these
.snap.newfiles (they're not from my changes):Assistant
Let me also see what the diff looks like:
Assistant
Good. Now let me also look at this from a different angle. The fix is in
resolve_type_with_arity. But there are other places whereresolve_type_nameis called. Let me check if those are affected:Assistant
Only one other place uses
resolve_type_namedirectly - to check ifUnitis defined. My change doesn't affect this sinceUnitisn't a Value.Let me also check that my fix doesn't break
Unit-like behavior. The special case for Unit:Assistant
This is fine. If the user defines
Unitas a type,resolve_type_namereturns Some. If the user definesUnitas a const, with my change... wait actually, my change doesn't affectresolve_type_name. I only changedresolve_type_with_arity. Let me re-verify:Assistant
Good, my change only affects
resolve_type_with_arity. Now let me look at the bindgen side - should I also rename the const? Let me think about this from the user's perspective:The user is dealing with the discordgo package. The discordgo
Locale.Unknownconst is a value representing the "unknown locale". After my fix, the user can:- Use
Slice<Unknown>(unqualified) in the discordgo.d.lis file (no shadowing because we fall through to prelude) - Use
discordgo.Unknown(qualified) only as a value, not as a type - The const value
Unknown(ordiscordgo.Unknown) is still accessible in value position
This works! The bindgen doesn't need to be changed.
However, looking at the issue from the description:
Unknown constant in go dependencies conflicts with Lisette's built-in Unknown type
The issue's recommendation says "or the binding generator should qualify/disambiguate". I think my fix is sufficient.
But wait, let me also reconsider: my fix is in the resolver, so it handles ANY type that might be shadowed, not just
Unknown. This is the more general fix.Let me also think about if this could cause issues. For example:
- A user has
pub const Foo: int = 5in their module - They want to write
let x: Foo = 5in their own code - My fix would skip
Fooas a value and fall through to prelude - but prelude doesn't haveFoo - Result: type not found error
But wait, they CAN'T have both
pub const FooandFooas a type. Lisette forbids that. So this isn't an issue.What about this case:
- A user has
pub const Foo: int = 5in their module - They write
let x: Foo = 5→ my fix would skip Foo, try prelude, prelude doesn't have Foo, error: "type not found"
Hmm but this is wrong! The user CAN'T have
let x: Foo = 5if Foo is a const. They can only useFooas a value:let x = Foo. So the error is correct.OK so my fix is safe. Let me now also think about what happens when:
- The qualified form
discordgo.Unknownis used as a TYPE in user code - Current behavior (before my fix): type_not_found (wait, no - let me check)
Actually wait. Let me trace through the qualified case
discordgo.Unknown:Before my fix:
resolve_type_with_arity("discordgo.Unknown", 0)resolve_type_name("discordgo.Unknown")returns(discordgo.Unknown, ty)because the discordgo module has a constUnknownarity_of(ty) == 0 == expected_arity, returnsclassify_non_type_namechecks the body - it's a Value, raises "value_in_type_position" error
After my fix:
resolve_type_with_arity("discordgo.Unknown", 0)resolve_type_name("discordgo.Unknown")returns(discordgo.Unknown, ty)(same as before)resolved_is_valueis true. Withtype_name.contains('.')is true, we DON'T take the fallback patharity_of(ty) == 0 == expected_arity, returns the same as beforeclassify_non_type_nameraises error - same as before ✓
So the qualified case still produces the error. Good.
Now let me also verify my fix with one more test case - "discordgo.Unknown" in a type, but via indirect reference:
- Use
Assistant
Wait, the test isn't being picked up. Let me check:
Assistant
I forgot to add
mod repro_testto mod.rs:Assistant
All tests pass. Let me run the full test suite again to confirm I don't break anything:
Assistant
3576 passed (vs 3572 on master) and same 1576 failures (pre-existing, unrelated).
Now let me clean up my temporary test files:
Assistant
All the .snap.new files are pre-existing. Let me verify by checking if they exist on master:
Assistant
Yes, these
.snap.newfiles are pre-existing on master. They're test failures that exist before my changes. Let me clean them up:Assistant
Let me see the final diff:
Assistant
Now let me think about whether there might be unintended consequences. Let me check how this interacts with other resolvers:
Assistant
resolve_type_with_arityis called fromconvert_to_typeto resolve the type name. So my fix affects type resolution. Value resolution useslookup_qualified_namedirectly which I didn't modify.Let me re-verify by inspecting code paths more thoroughly:
Assistant
Let me check primitives.rs:244 - this is where value lookup happens:
Assistant
So in primitives.rs, value lookup uses
lookup_qualified_namedirectly to find the qualified name, then the actual type lookup happens vialookup_type. Let me look atlookup_type:Assistant
So
lookup_typeis used for value position, whileresolve_type_with_arityis used for type position. My change only affectsresolve_type_with_arity. Value resolution is unaffected.Let me also check the bindgen. While my fix in the resolver is sufficient, let me think about whether the bindgen should ALSO avoid emitting conflicting names. Let me look at it more carefully:
Actually, I think the resolver fix is the right approach. The bindgen doesn't know which Go constant names might shadow Lisette built-in types. The resolver can handle this dynamically.
But I want to also consider this from a different angle: what if there's another package that has
pub const int: int = 5? With my fix:Slice<int>in that .d.lis file works correctly (uses prelude'sint)let x = intin that .d.lis file works correctly (uses the const)
Let me verify this case via the test again:
Assistant
Let me also clean up:
Assistant
Now let me also think: should the bindgen be modified? Let me re-read the issue:
Unknown constant in go dependencies conflicts with Lisette's built-in Unknown type
The issue title says it's about the constant
Unknownin Go dependencies conflicting with Lisette's built-inUnknown. My fix solves this by making the resolver prefer prelude'sUnknownwhen used as a type.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.
The expected behavior lists two options:
- The built-in
Unknowntype takes precedence (my fix achieves this) - The binding generator qualifies/disambiguates (we don't do this)
Let me consider: should we ALSO modify the bindgen? Let me think...
If a Go package has
const Unknown = 0, the bindgen would generatepub const Unknown: int = 0(or whatever type). When this .d.lis file is used in another file,Unknownwould shadow... wait no, the binding generator produces separate .d.lis files. The user's code is separate from the generated .d.lis.Looking at the discordgo.d.lis case more carefully, the issue is:
- discordgo's .d.lis has
pub const Unknown: Locale = ""AND usesUnknownin type positions - These type positions are inside the same .d.lis file
So the issue is internal to the generated .d.lis file. My fix handles this case correctly.
But what about user code that imports discordgo?
let x = discordgo.Unknown(value usage) - works finelet x: discordgo.Unknown = ...(type usage) - value_in_type_position errorlet x: Slice<discordgo.Unknown> = [](type usage) - value_in_type_position error
This is acceptable behavior because the user is explicitly trying to use the const value as a type, which is incorrect.
Hmm, but wait - in Go code, there's no need for
discordgo.Unknownas a TYPE since the const is a value. But what about types likeinterface{}?Let me think: in Go,
Loggerisfunc(msgL, caller int, format string, a ...interface{}). Theinterface{}is Go'sany. When bindgen converts this to Lisette, it becomesfn(int, int, string, VarArgs<Unknown>). SoUnknownhere is the Lisette built-in, not discordgo'sUnknownconst.In the discordgo.d.lis file, the user (bindgen) wrote
VarArgs<Unknown>. Since the .d.lis is generated, it's the bindgen's responsibility to use the correct name. The bindgen correctly generatesUnknownbecause that's the name mapped from Go'sinterface{}. So we should make thisUnknownresolve to the prelude, not the discordgo const.This is exactly what my fix does.
Let me also check what the Go code emitter does to ensure it works:
- The built-in
Assistant
So the Go emitter maps ANY "Unknown" qualified name to "any" - this is good. So when the discordgo Unknown value reaches the Go emitter, it would also be mapped to
any, which is wrong.Hmm, let me think. With my fix:
discordgo.Unknown(qualified): still produces value_in_type_position error (because my fix preserves the qualified path)Slice<Unknown>(unqualified, resolves to prelude): goes to the prelude, qualified name =prelude.Unknown. The Go emitter mapsUnknowntoanycorrectly.
So my fix is correctly addressing the original issue.
Now let me also think about: should my fix ALSO be applied to the bindgen code to rename the const? Let me check the issue's recommendation again:
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.
It says "or" - either approach is acceptable. My fix achieves the first option.
Actually, looking again at the issue description, I realize there's potentially another approach: what if we make
lookup_qualified_nameskip Value definitions when called for TYPE resolution? That's cleaner than my approach.Hmm, let me re-think. My fix is in
resolve_type_with_arity. Let me look at this function once more:Assistant
OK my implementation looks good. Let me also test the
() => Unit()case - when the user defines their own Unit:Assistant
My fix doesn't break this case. Let me clean up:
Assistant
Now let me also check if I should consider what happens when the bindgen itself runs. The bindgen is a separate process, so my changes wouldn't affect its output. The bindgen generates code that uses
Unknownin type positions. When that code is later compiled by Lisette, my fix kicks in.Let me also see if there's a potential issue with the bindgen by looking at the actual bindgen test:
Assistant
No Go installed. So I can't easily run the bindgen here. But the bindgen is supposed to generate code using
Unknownas a type. With my fix in the resolver, that generated code will work correctly.Let me verify my final understanding and look at the diff one more time:
Assistant
Now let me also re-confirm the test against the actual discordgo issue by generating a fake discordgo .d.lis:
Assistant
Oh wait, there's a
get_unknownin prelude? Let me check:Assistant
Interesting, the prelude_function check checks for ANY function name in the prelude.
get_unknownis in some way there. Let me look:Assistant
Hmm, weird. The error says
get_unknownis a prelude function. Let me check what functions exist in the prelude:Assistant
So there's no
get_unknownin the prelude. But the error says so. Let me look at the prelude_shadowing:Assistant
Let me look at what definitions are in the prelude module:
Assistant
Ah, the test harness defines
get_unknownas a prelude function! So my test should use a different name. Let me fix:Assistant
All 3 tests pass. Let me also test that the scenario for the discordgo Marshal/Unmarshal works with proper Result types:
Assistant
OK, this test has other errors because
Newis not in the typedef andprintlnis not a builtin. Let me make a simpler test:Assistant
The test passes. Let me clean up:
Assistant
Now let me also think about whether my fix should be more conservative. What if the
resolve_type_namereturns anInterfaceorTypeAliasthat's a special case? Let me re-read the diff to make sure it's solid:Assistant
Now let me also see if there's a test that I could formally add. Looking at the existing test patterns for unit errors:
Assistant
Let me see what kind of tests would be appropriate. The note says "UNDER NO CIRCUMSTANCES should you modify existing tests or add new tests to the repository. This will lead to an error in the system that evaluates your performance."
So I should NOT add new tests. Let me just keep the source code change.
Let me also make sure I've checked all the affected code paths:
Assistant
OK, that's a different function. Let me make sure my fix is in the right place.
Assistant
Good - the flow is:
convert_to_typecallsresolve_type_with_arityto get the resolved type- If found, calls
classify_non_type_nameto check if it's actually a type - If it's a value, raises
value_in_type_positionerror
My fix in
resolve_type_with_aritymakes it skip Value definitions for unqualified names. For qualified names, it still returns them, which then triggers the normalvalue_in_type_positionerror.Now let me also run the broader test suite (other crates) to make sure nothing else breaks:
Assistant
All workspace lib tests pass. Now let me check the binary tests:
Assistant
All workspace bin tests pass too. Now let me verify the integration tests:
Assistant
All e2e tests pass. Let me also check the LSP tests:
Assistant
All LSP tests pass.
Now let me make a final verification of the change with my reproducer:
Assistant
Let me also clean up and run one final full test to make sure nothing is broken:
Assistant
Same as master. My fix doesn't introduce new failures.
Let me also make sure my fix runs through the entire test suite (including the build/e2e tests):
Assistant
All workspace tests pass except the pre-existing 1576 failures in the suite test (unrelated to my changes).
Let me also clean up the test snapshots that may have been generated by cargo test:
Assistant
Now let me view the final diff:
Assistant
The change is minimal and focused. Now let me write up my reasoning for the checklist:
CHECKLIST:
-
If an error was reported in the issue description, I have successfully reproduced it.
- YES. I created test cases that simulate the discordgo scenario where
Unknownis declared as a const in a .d.lis file and used in type positions. Before my fix, this raisedresolve.value_in_type_positionerrors. After my fix, these resolve correctly.
- YES. I created test cases that simulate the discordgo scenario where
-
If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- YES. My modified test cases pass successfully after the fix. The discordgo-like typedef with const
Unknown: Locale = ""and function signatures usingUnknownin type positions now compiles cleanly.
- YES. My modified test cases pass successfully after the fix. The discordgo-like typedef with const
-
I have thought about edge cases and made sure my fix handles them as well.
- YES. I considered several edge cases:
- Qualified case
discordgo.Unknownin type position: still raises value_in_type_position (preserves existing behavior) - Unqualified case
Unknownshadowing prelude type: now resolves to prelude's Unknown - Const value usage like
let x = discordgo.Unknown: still works (value resolution unchanged) - Other prelude types like
int,boolbeing shadowed by values: handled by the same logic - Const in match pattern like
discordgo.Locale.Unknown: works because the qualified prefix is preserved - User-defined
Unittype: still works (Unit special-casing unaffected)
- Qualified case
- YES. I considered several edge cases:
-
I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass.
- YES. I ran:
- All workspace lib tests: 154 passed, 0 failed
- All workspace bin tests: 17 passed, 0 failed
- LSP tests: 502 passed, 0 failed
- Full test suite: 3572 passed, 1576 failed (the same 1576 failures exist on master without my changes - they are pre-existing snapshot/format issues unrelated to my change)
- My fix doesn't introduce any new test failures.
- YES. I ran:
The fix is in
/lisette/crates/semantics/src/checker/registration/convert.rsin theresolve_type_with_arityfunction. It modifies the function to check whether the resolved qualified name refers to a value definition (not a type). If it is a value AND the type_name is unqualified (no.), the function falls through to look for the name in the prelude. This way:- For unqualified names: prelude types like
Unknown,int,booltake precedence over module-local value definitions with the same name. - For qualified names: the user's explicit reference (e.g.,
discordgo.Unknown) is preserved, and the existingvalue_in_type_positiondiagnostic remains for that case.
-
Assistant
The fix is clean and ready. Let me submit:
Assistant
Wait, let me double-check there are no remaining untracked .snap.new files. Let me also be more thorough:
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
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →