Unions: two may have a case of one name; which name wins, as it is

A case of one name in two unions is chosen by type, then by scope, and
the manual says so in place of "cannot both have a case called Red".
Writing programs said two imports offering one name, a type among them,
resolved to the later import; a use is refused until the program says
which, except for cases of different unions.

🤖 Generated with [ECA](https://eca.dev)

Co-Authored-By: eca-agent <git@eca.dev>
This commit is contained in:
Linus Björnstam 2026-10-22 11:27:57 +02:00
parent 684745d6c0
commit 1a407720a9
2 changed files with 25 additions and 3 deletions

View file

@ -195,7 +195,7 @@ Note that @code{only} and @code{except} apply exclusively to functions and macro
0)
}|
Types are strictly scoped to the module that declared them. If two imported libraries each declare their own @code{Card} type, they remain distinct types; the unqualified name @code{Card} simply resolves to whichever import came last. To disambiguate between them, use @code{prefix-types}:
Types are strictly scoped to the module that declared them. If two imported libraries each declare their own @code{Card} type, they remain distinct types, and writing the unqualified name @code{Card} is an error until you say which one you mean. To tell them apart, use @code{prefix-types}:
@codeblock[#:lang "bjolang"]|{
(import (prefix-types "poker.bjo" "P/")
@ -210,7 +210,7 @@ When multiple definitions share the same identifier, name resolution follows thr
@read-list{
- Local definitions take precedence over imported names.
- For collisions between two imports, the later import shadows the earlier one. This shadowing behavior is how modules can freely override names from the prelude, which is loaded as the very first import.
- A name the prelude offers is overridden by any other import's, which is how a module can freely replace a prelude name. Between two other imports that offer one name as two different things, importing both is fine, but writing the name is an error until you say which one you mean, with @code{only}, @code{except} or a prefix. Two cases of different unions are the exception: which one a use means is decided by its type, as described for unions in Part 1.
- Explicit renames or aliases created by import modifiers or @code{:alias} must be unique. If an alias collides with an existing name, the compiler raises an error to prevent ambiguity.
}