You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
std.prql declares std.text and std.date twice; the type aliases are silently discarded #6146
The module def comes later and replaces the type decl, so the modules win and the two type lines are dead — std.text and std.date are not reachable as types:
$ prqlc compile 'let f = func x <std.text> -> x
from t
derive {y = f "a"}'
Error: expected a type, but found Module(Module { names: {"contains": …
Bare <text> still works, because the lexer resolves the primitive type keywords directly rather than going through std. So nothing is broken for users today; the two type declarations are just silently discarded.
Why it matters. It blocks a resolver cleanup. fold_module_def_stmt currently replaces whatever declaration sits under the module's name. A PR in flight changes it to merge when the existing declaration is also a module, which fixes silently-dropped declarations across files. The natural companion — erroring when the existing declaration is not a module, so that let x = 1 followed by module x { … } stops silently dropping x, matching how let/type duplicates are already reported — can't land while std.prql relies on the replacement. With that check in place, loading the standard library fails with duplicate declarations of std.text.
The question is what std.text should mean, which is a language decision rather than a resolver one:
Drop the type text / type date lines. They're already inert, so this is behaviour-preserving, and it makes std.text unambiguously the module. But it leaves the primitives list in std.prql inconsistent — int, float, bool, time, timestamp would keep their type aliases while text and date wouldn't.
Rename the modules (std.str? std.text_fns?) so the type aliases survive as types. Breaking change for anyone writing std.text.lower explicitly.
Let a name hold both a type and a module, resolved by context. Largest change; the resolver would need per-namespace lookup.
Option 1 is the cheapest and matches today's observable behaviour, but it's worth a maintainer's call before I write it. Once whichever option lands, the non-module half of the duplicate check in fold_module_def_stmt can follow.
Option 2 would be a pretty substantial breaking change; I don't support it at all.
I thought option 3 was appealing, until I realized it would probably have unintended effects on things like #6104 (simple enums).
There's another option which you didn't suggest... which is honestly undocumented behavior anyway, and something that I would sort of hope to patch out of the resolver in the future. We could use the _self name to define std.text as both a namespace and a type:
# instead of
# type text = text
module text {
type _self = text
let lower = column -> <text> internal std.text.lower
let upper = column -> <text> internal std.text.upper
# ...
}
I tried this, and the test suite passes with some snapshot updates. There is one change to an error message that is not great:
Source: prqlc/prqlc/tests/integration/error_messages.rs:185
─────────────────────────────────────────────────────────────
Expression: compile(
r#"
from a
derive date = x
select date
"#,
)
.unwrap_err()
─────────────────────────────────────────────────────────────
-old snapshot
+new results
────────────┬────────────────────────────────────────────────
4 4 │ 4 │ select date
5 5 │ │ ──┬─
6 6 │ │ ╰─── Ambiguous name
7 7 │ │
8 │- │ Help: could be any of: std.date, this.date
8 │+ │ Help: could be any of: std.date._self, this.date
9 9 │ │
10 10 │ │ Note: available columns: date
11 11 │ ───╯
────────────┴────────────────────────────────────────────────
_self works, and the error-message regression is fixable — #6151 implements it.
On the ambiguous-name hint: it comes from ambiguous_error formatting each candidate ident verbatim, so dropping a trailing _self part there restores could be any of: std.date, this.date — test_ambiguous needs no snapshot change.
There was a second leak you wouldn't have hit unless you annotated with the module name. A type mismatch against <std.date> reported:
╰── function f, param `x` expected type `_self`, but found type `int`
Help: Type `_self` expands to `date`
where std.int (an ordinary type int = int alias) says expected type `int` . That one is fold_type_def_stmt setting ty.name = ident.name; naming a type _self after its containing module instead fixes it. With both, the PR has no user-visible message changes at all — the remaining snapshot churn is std.prql byte offsets.
I also confirmed it unblocks what motivated the issue: with a temporary check rejecting a module def over a non-module decl, the standard library loads clean and let x = 1 followed by module x { … } reports duplicate declarations of x. That check isn't in #6151 — it belongs on top of #6147.
Worth noting for the record that this leaves std.text and std.date declared differently from the other primitives, and leans on _self — which you'd rather patch out of the resolver eventually. If you'd prefer option 1 (just delete the two inert type lines) on those grounds, that's a smaller diff and I'm happy to swap; #6151 is the version that keeps them usable as types.
As far as I know, all of the type x = x lines are inert at the moment, since PRQL's type system is still a bit in flux. However, the #6151 fix at least means that declaring a type <text> refers to a real type and not a module... so that seems to be a tiny improvement.
I'm broadly in favor of the approach in #6151 as a bandaid. The true fix in my view would probably be something like defining module types { ... } in std.prql and then putting all of the core types in there. Then, extend the redirects defined at the root module to include Ident::from_path(vec![NS_STD, "types"]) so that the existing unqualified names resolve properly. I tested that out but quickly ran into an issue (it was trying and failing to resolve the name std.relation but I could not easily determine where it got that mangled name). Something to think about...
std.relation isn't mangled — it's hardcoded. fold_var_def_stmt stamps it on as the implicit type of main:
if def.name == "main"{
def.ty = Some(Ty::new(TyKind::Ident(Ident::from_path(vec!["std","relation",]))));}
It's an absolute path, so a root redirect can't rescue it: lookup prepends the redirect to the whole ident, so std.types + std.relation tries std.types.std.relation. Changing that one line to ["std", "types", "relation"] is the only other source edit the restructure needs.
I prototyped your module types { … } sketch with that fix and it works end-to-end — 475 tests pass. One refinement: put the redirect on the std module rather than the root. A direct hit beats redirects, so date still resolves to std.date (the module) and std.types.date never becomes a second candidate — which means test_ambiguous keeps could be any of: std.date, this.date unchanged. With the redirect at the root as you sketched, that help line gains a third entry. Either way the remaining snapshot churn is node ids and byte offsets from the extra statement; no SQL changes.
It also closes this issue on its own, without _self: std.text is unambiguously the module and std.types.text is the type, so there's no duplicate left to reconcile. I re-ran the probe from my last comment — a temporary check rejecting a module def over a non-module decl — and the standard library loads clean, while let x = 1 / module x { … } reports duplicate declarations of x.
Two things I'd flag honestly. Bare date and text still resolve to the modules under this scheme, so the types are reachable only as std.types.date / std.types.text — bare <date> annotations are unaffected since the lexer handles the primitive keywords. And my redirect was a special-case on current_module_path == ["std"] inside fold_module_def_stmt; a real change wants a cleaner way to attach it.
Happy to open this as an alternative to #6151 if you'd rather take the real fix now — the diff is smaller than I expected. Otherwise #6151 stands as-is.
Prototype diff and verification
std.prql — wrap the primitives block (type int through type transform) in module types { … }, unchanged otherwise.
cargo insta test -p prqlc — 475 passed, 0 failed, plus doctests. error_messages.rstest_ambiguous needed no edit.
Accepted snapshots: 43 files, all debug_lineage node-id/input_id shifts (+1) and std.prql byte offsets. No .sql output changed.
from t | select {a} compiles; before the stmt.rs fix it fails with Error: Unknown name `std.relation` — that's the error you hit.
let f = func x <std.types.text> -> x compiles; <text> still works; a mismatch against <std.types.date> says expected type `date` with no _self leak.
Duplicate probe: added a check in fold_module_def_stmt erroring when the existing decl at the path is not a module. Standard library loads clean; let x = 1 + module x { let y = 2 } errors with duplicate declarations of x.
I ran the prqlc suite, not the cross-binding matrix.
Yes, let's open this as an alternative. Although I do prefer the approach of adding Ident::from_path(vec![NS_STD, "types"]) in the root module rather than the special-case handling of fold_module_def_stmt, because:
It avoids the strange special-case handling
Both date and text are handled as primitive type keywords anyway, so there really isn't a need to worry about it
And I think that the change to the error message (adding std.types.date) is not really a big deal... for the simple reason that I think that error message and behavior is probably unnecessary in the long run. I'd rather PRQL be smart enough to know that when you say select date and the only candidates are a type, a module, and a column -- it should choose the column, because both the type and the module references will never work as an argument to select. This requires enhancing the type system, though, which is still TBD.
Activity
prql-bot commentedon Aug 6, 2026
The merge half of this is now open as #6147; the non-module duplicate check waits on the decision here.
kgutwin commentedon Aug 6, 2026
Option 2 would be a pretty substantial breaking change; I don't support it at all.
I thought option 3 was appealing, until I realized it would probably have unintended effects on things like #6104 (simple enums).
There's another option which you didn't suggest... which is honestly undocumented behavior anyway, and something that I would sort of hope to patch out of the resolver in the future. We could use the
_selfname to definestd.textas both a namespace and a type:I tried this, and the test suite passes with some snapshot updates. There is one change to an error message that is not great:
But I suppose that could be fixed somehow.
prql-bot commentedon Aug 6, 2026
_selfworks, and the error-message regression is fixable — #6151 implements it.On the ambiguous-name hint: it comes from
ambiguous_errorformatting each candidate ident verbatim, so dropping a trailing_selfpart there restorescould be any of: std.date, this.date—test_ambiguousneeds no snapshot change.There was a second leak you wouldn't have hit unless you annotated with the module name. A type mismatch against
<std.date>reported:where
std.int(an ordinarytype int = intalias) saysexpected type `int`. That one isfold_type_def_stmtsettingty.name = ident.name; naming atype _selfafter its containing module instead fixes it. With both, the PR has no user-visible message changes at all — the remaining snapshot churn is std.prql byte offsets.I also confirmed it unblocks what motivated the issue: with a temporary check rejecting a module def over a non-module decl, the standard library loads clean and
let x = 1followed bymodule x { … }reportsduplicate declarations of x. That check isn't in #6151 — it belongs on top of #6147.Worth noting for the record that this leaves
std.textandstd.datedeclared differently from the other primitives, and leans on_self— which you'd rather patch out of the resolver eventually. If you'd prefer option 1 (just delete the two inerttypelines) on those grounds, that's a smaller diff and I'm happy to swap; #6151 is the version that keeps them usable as types.kgutwin commentedon Aug 6, 2026
As far as I know, all of the
type x = xlines are inert at the moment, since PRQL's type system is still a bit in flux. However, the #6151 fix at least means that declaring a type<text>refers to a real type and not a module... so that seems to be a tiny improvement.I'm broadly in favor of the approach in #6151 as a bandaid. The true fix in my view would probably be something like defining
module types { ... }instd.prqland then putting all of the core types in there. Then, extend theredirectsdefined at the root module to includeIdent::from_path(vec![NS_STD, "types"])so that the existing unqualified names resolve properly. I tested that out but quickly ran into an issue (it was trying and failing to resolve the namestd.relationbut I could not easily determine where it got that mangled name). Something to think about...prql-bot commentedon Aug 6, 2026
std.relationisn't mangled — it's hardcoded.fold_var_def_stmtstamps it on as the implicit type ofmain:It's an absolute path, so a root redirect can't rescue it:
lookupprepends the redirect to the whole ident, sostd.types+std.relationtriesstd.types.std.relation. Changing that one line to["std", "types", "relation"]is the only other source edit the restructure needs.I prototyped your
module types { … }sketch with that fix and it works end-to-end — 475 tests pass. One refinement: put the redirect on thestdmodule rather than the root. A direct hit beats redirects, sodatestill resolves tostd.date(the module) andstd.types.datenever becomes a second candidate — which meanstest_ambiguouskeepscould be any of: std.date, this.dateunchanged. With the redirect at the root as you sketched, that help line gains a third entry. Either way the remaining snapshot churn is node ids and byte offsets from the extra statement; no SQL changes.It also closes this issue on its own, without
_self:std.textis unambiguously the module andstd.types.textis the type, so there's no duplicate left to reconcile. I re-ran the probe from my last comment — a temporary check rejecting a module def over a non-module decl — and the standard library loads clean, whilelet x = 1/module x { … }reportsduplicate declarations of x.Two things I'd flag honestly. Bare
dateandtextstill resolve to the modules under this scheme, so the types are reachable only asstd.types.date/std.types.text— bare<date>annotations are unaffected since the lexer handles the primitive keywords. And my redirect was a special-case oncurrent_module_path == ["std"]insidefold_module_def_stmt; a real change wants a cleaner way to attach it.Happy to open this as an alternative to #6151 if you'd rather take the real fix now — the diff is smaller than I expected. Otherwise #6151 stands as-is.
Prototype diff and verification
std.prql— wrap the primitives block (type intthroughtype transform) inmodule types { … }, unchanged otherwise.prqlc/prqlc/src/semantic/resolver/stmt.rs:if def.name == "main" { def.ty = Some(Ty::new(TyKind::Ident(Ident::from_path(vec![ - "std", "relation", + "std", "types", "relation", ])))); }and in
fold_module_def_stmt, the redirect (special-cased for the probe):kind: DeclKind::Module(Module { names: HashMap::new(), - redirects: Vec::new(), + redirects: if self.current_module_path == ["std"] { + vec![Ident::from_name("types")] + } else { + Vec::new() + }, shadowed: None, }),Verification, all on
7bd7499:cargo insta test -p prqlc— 475 passed, 0 failed, plus doctests.error_messages.rstest_ambiguousneeded no edit.debug_lineagenode-id/input_idshifts (+1) andstd.prqlbyte offsets. No.sqloutput changed.from t | select {a}compiles; before thestmt.rsfix it fails withError: Unknown name `std.relation`— that's the error you hit.let f = func x <std.types.text> -> xcompiles;<text>still works; a mismatch against<std.types.date>saysexpected type `date`with no_selfleak.fold_module_def_stmterroring when the existing decl at the path is not a module. Standard library loads clean;let x = 1+module x { let y = 2 }errors withduplicate declarations of x.I ran the
prqlcsuite, not the cross-binding matrix.kgutwin commentedon Aug 6, 2026
Yes, let's open this as an alternative. Although I do prefer the approach of adding
Ident::from_path(vec![NS_STD, "types"])in the root module rather than the special-case handling offold_module_def_stmt, because:dateandtextare handled as primitive type keywords anyway, so there really isn't a need to worry about itstd.types.date) is not really a big deal... for the simple reason that I think that error message and behavior is probably unnecessary in the long run. I'd rather PRQL be smart enough to know that when you sayselect dateand the only candidates are a type, a module, and a column -- it should choose the column, because both the type and the module references will never work as an argument toselect. This requires enhancing the type system, though, which is still TBD.