ISSUE DESCRIPTION Unknown constant in go dependencies conflicts with Lisette's built-in…
- User
ISSUE DESCRIPTION
Unknown constant in go dependencies conflicts with Lisette's built-in Unknown type The discordgo package defines a constant named
Unknown(used for unrecognized types/events), which conflicts with Lisette's built-in Unknown type. When Lisette generates bindings for discordgo, any function signature that uses Unknown as a type parameter is misinterpreted — the compiler sees the discordgo value Unknown in a type position, causing a resolve.value_in_type_position error.Error output:
🔴 Value in type position ╭─[go:github.com_bwmarrin_discordgo.d.lis:4693:46] 4692 │ /// Logger can be used to replace the standard logging for discordgo 4693 │ pub var Logger: fn(int, int, string, VarArgs<Unknown>) -> () · ───┬─── · ╰── expected type, found value 4694 │ ╰──── help: Only a type is allowed here · code: [resolve.value_in_type_position] 🔴 Value in type position ╭─[go:github.com_bwmarrin_discordgo.d.lis:4695:21] 4694 │ 4695 │ pub var Marshal: fn(Unknown) -> Result<Slice<byte>, error> · ───┬─── · ╰── expected type, found value 4696 │ ╰──── help: Only a type is allowed here · code: [resolve.value_in_type_position] 🔴 Value in type position ╭─[go:github.com_bwmarrin_discordgo.d.lis:4697:36] 4696 │ 4697 │ pub var Unmarshal: fn(Slice<byte>, Unknown) -> Result<(), error> · ───┬─── · ╰── expected type, found value 4698 │ ╰──── help: Only a type is allowed here · code: [resolve.value_in_type_position]Root Cause
discordgodefines a constant named Unknown (e.g. Unknown Locale). Lisette also has a built-in type named Unknown used to represent opaque/untyped Go values in bindings. When the binding generator emits Unknown in a type position, the name resolves to the discordgo constant value instead of the Lisette type, triggering the error.Expected Behavior
Lisette's built-in Unknown type should take precedence in type positions, or the binding generator should qualify/disambiguate imported names that shadow built-in types.
Reproduction
Add github.com/bwmarrin/discordgo as a dependency and run lis run. The error appears immediately during binding resolution without any user-written code.
import "go:fmt" import "go:github.com/bwmarrin/discordgo" const TOKEN = "token" fn main() { let _discord = try { discordgo.New("Bot" + TOKEN)? } fmt.Println("Hello world!") } - Assistant
I’ll first map the repository and locate the binding generation and name-resolution code, then reproduce the shadowing with the most focused existing test or a temporary fixture before deciding whether the correct fix belongs in generation or resolution.
- Assistant
ripgrepis unavailable, so I’ll usegrep/find. The project is Rust with a Go bindgen; I’m narrowing down whereUnknownis emitted and how namespaces are resolved, along with the test conventions for resolver diagnostics and generated declarations. - Assistant
A key clue is that the checked-in
go/constantbinding already contains bothpub const Unknownand signatures using the built-inUnknown, so the bug is broader than discordgo and can likely be reproduced without downloading anything. I’ll inspect resolver scope construction and run the relevant semantic tests against a tiny source module that declares a value and uses the same name as a built-in type. - Assistant
There is already a dedicated
predeclared_shadowingpass whose module comment describes this exact failure mode. I’ll verify whether it is wired in, what names it handles, and whether it merely rejects declarations rather than preserving dependency bindings. This may be an incomplete or over-broad implementation in the repository baseline. - Assistant
The existing pass is unrelated to Lisette’s
Unknown: it protects Go emission namesany/comparable. The resolver currently resolves a constructor name through a unified definition lookup and only afterward diagnoses values. The likely robust fix is contextual lookup: in a type position, prefer an actual type definition (including prelude built-ins) over a same-named value, while retaining the value for expression positions. I’ll inspectresolve_type_with_arity, definition storage/lookup ordering, and duplicate-name semantics before changing it. - Assistant
I need the exact lookup mechanics before selecting a minimal patch. In particular, unprefixed modules appear to merge symbols into one scope, so I’ll examine whether there is enough qualified metadata to bypass only a shadowing value and locate
prelude.Unknown, without changing normal local type shadowing or qualified package behavior. - Assistant
resolve_type_with_arityalready has a prelude fallback, but only for arity mismatch—not when the first match is a value of matching arity (constants have arity zero). That pinpoints the defect. I’ll confirm lookup ordering and definition classification, then reproduce using the existinggo:constanttypedef through the CLI or semantics harness. The minimal semantic change should fall back to the prelude when the local match is not a type, while preserving diagnostics if no same-named prelude type exists. - Assistant
The lookup is indeed value/type-unified. Before editing, I’ll make a temporary Lisette project outside the repository containing
const Unknown = 0and a function annotationUnknown; this directly exercises the same resolver path as a generated dependency and avoids modifying tests. I’ll use the project CLI help to determine the lightest check command. - Assistant
The toolchain is available; only the package name differs. I’ll read the CLI manifest and project conventions, then run the direct reproduction.
- Assistant
I’ll copy only the minimal project metadata pattern into
/tmpand invokelis check. If user declarations namedUnknownare separately prohibited, I can instead use a temporary.d.lisdependency fixture, but first the direct source should demonstrate resolver behavior. - Assistant
Now I’ll execute the temporary reproduction and capture the expected
resolve.value_in_type_positionfailure before patching. - Assistant
The reproduction confirms the exact diagnostic. There are two plausible scopes:
- Special-case only
Unknown, matching the reported built-in collision and minimizing language changes. - Treat type/value namespaces contextually for all prelude types, which could silently reinterpret intentional errors such as a local function named like a built-in.
Because the expected behavior specifically says the built-in
Unknownshould take precedence and the resolver intentionally emits “value in type position” diagnostics, I’ll implement a narrowUnknownfallback inresolve_type_with_arity: only for unqualifiedUnknown, only when the first resolution is a value, and only when the prelude definition exists with matching arity. Qualified names likepkg.Unknownmust continue to resolve to package members and be diagnosed if used as types. - Special-case only
- Assistant
The patch is formatted and clean. I’ll rebuild the CLI and rerun the same temporary project. Success here means the shadowing diagnostic disappears; the unrelated deliberate fixture errors may remain, so I’ll specifically check that
resolve.value_in_type_positionis absent and then create a valid.d.lis-style dependency reproduction to get a fully successful analysis. - Assistant
The exact diagnostic is gone. For a clean end-to-end confirmation using an actual generated binding, the repository already ships
go/constant.d.lis, which has the same collision (pub const UnknownplusMake(x: Unknown)). I’ll replace the temporary source with a valid program importinggo:go/constant; if analysis succeeds, it validates dependency typedef resolution without introducing a repository test. - Assistant
The real generated
go/constantbinding now analyzes successfully. I’ll check two edge cases to ensure the fallback is not over-broad: explicitly qualifiedconstant.Unknownshould remain a value-in-type error, while a genuine user-defined type namedUnknownshould remain the selected type rather than being replaced by the prelude built-in. Then I’ll run the semantics and UI test suites. - Assistant
The qualified edge case behaves correctly. Genuine user type shadowing is independently rejected by an existing diagnostic, so it cannot be a valid ambiguity; importantly, the patch only classifies
DefinitionBody::Value, leaving type resolution behavior unchanged.I’ll now run crate-level semantics tests and the repository’s UI tests. Since this changes diagnostics only in the intended collision, existing value-in-type tests should remain unchanged.
- Assistant
All 54 semantics unit tests pass. The UI command used the wrong package ID (
tests, notlisette-tests), so I’ll rerun it correctly rather than treating that invocation error as validation. - Assistant
The broad substring filter
uiunintentionally selected many non-UI tests (e.g. names containing “build”) and 175 failed due environment/setup. I’ll inspect the first failures to verify they are unrelated, then identify the test module’s exact UI namespace and run that target precisely (likelyui::). - Assistant
Those failures are unrelated snapshot mismatches in
spec::build::*, selected because “build” containsui; the test run also created.snap.newartifacts, which I’ll remove. The exact namespace isui::, so I’ll rerun with that filter. - Assistant
Validation is complete: 54 semantics unit tests and all 1,297 exact UI tests pass, and only the intended source file is modified. I’ll do a final diff/style audit to ensure no generated artifacts or accidental changes remain, then submit.
- Assistant
Checklist before submission:
- Reproduced the reported error: Yes. A temporary project with a value named
Unknownandfn(Unknown)produced the exactresolve.value_in_type_positiondiagnostic. The checked-ingo:go/constantbinding also provides a real generated-binding analogue. - Confirmed the fix resolves it: Yes. The original temporary reproduction no longer emits that diagnostic, and a valid program importing
go:go/constantand callingconstant.Makechecks with no issues. - Considered edge cases: Yes. The fallback is limited to unqualified built-in
Unknownshadowed by a value. Explicitconstant.Unknownstill correctly errors in type position, actual type definitions are not treated as shadowing values, and other value/type misuse diagnostics are unchanged. - Ran affected existing tests: Yes.
cargo test -p lisette-semanticspassed all 54 tests, andcargo test -p tests --test suite 'ui::'passed all 1,297 UI tests. Formatting and diff checks also pass.
I’ll now submit the single-file resolver fix.
- Reproduced the reported error: Yes. A temporary project with a value named
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.