Skip to content

A package and a package of its namespace written unquoted with table values: one dependency is dropped (silently in one order) instead of the key-path-conflict error #1043

Done

Description

@Sunrisepeak

What

docs/05-dependencies.md states that a package and a package of its namespace in one table (mcpplibs.mtest and mcpplibs.mtest.gtest) cannot both be written unquoted, and that the quoted key of one of them is their spelling. When both are written unquoted anyway:

  • with string values mcpp reports the conflict (error: mcpp.toml:7:25: error: key path conflict);
  • with inline-table values ({ path = … }, { version = …, features = […] }) it does not. The manifest is not valid TOML (Python's tomllib refuses it), mcpp accepts it and drops one of the two dependencies: with a warning that names something else in one order, and with no manifest diagnostic at all in the other.

The table form is the common one for the outer package: a dependency with features has to be a table.

Reproduce (mcpp 2026.11.27.1, Linux x86_64; the same on 2026.11.20.1)

mkdir -p repro/kit/src repro/extra/src repro/app/src && cd repro
printf '[package]\nnamespace = "acme"\nname = "kit"\nversion = "0.1.0"\n\n[targets.kit]\nkind = "lib"\n' > kit/mcpp.toml
printf 'export module acme.kit;\nexport int kit() { return 1; }\n' > kit/src/kit.cppm
printf '[package]\nnamespace = "acme.kit"\nname = "extra"\nversion = "0.1.0"\n\n[targets.extra]\nkind = "lib"\n' > extra/mcpp.toml
printf 'export module acme.kit.extra;\nexport int extra() { return 2; }\n' > extra/src/extra.cppm
printf 'import acme.kit;\nimport acme.kit.extra;\nint main() { return kit() + extra() == 3 ? 0 : 1; }\n' > app/src/main.cpp

A. The package first

# app/mcpp.toml
[package]
name = "app"
version = "0.1.0"

[dependencies]
acme.kit       = { path = "../kit" }
acme.kit.extra = { path = "../extra" }
$ python3 -c "import tomllib; tomllib.load(open('app/mcpp.toml','rb'))"
tomllib.TOMLDecodeError: Cannot mutate immutable namespace ('dependencies', 'acme', 'kit') (at line 7, column 39)

$ (cd app && mcpp build)            # exit 1
warning: [dependencies."acme.kit"] has unrecognized key 'extra' (ignored). It may be a typo, or a field a newer mcpp understands.
warning: …/app/src/main.cpp: module 'acme.kit.extra' imported but not provided in this build
error: build failed in app v0.1.0 (.)

$ (cd app && mcpp build --strict)   # exit 2
error: [dependencies."acme.kit"] has unrecognized key 'extra' (ignored). It may be a typo, or a field a newer mcpp understands.

acme.kit.extra is read as a field of the dependency acme.kit. The message suggests a typo or a newer mcpp; neither is the case, and it does not say that a dependency was lost.

B. The package of the namespace first

[dependencies]
acme.kit.extra = { path = "../extra" }
acme.kit       = { path = "../kit" }
$ python3 -c "import tomllib; tomllib.load(open('app/mcpp.toml','rb'))"
tomllib.TOMLDecodeError: Cannot overwrite a value (at line 7, column 37)

$ (cd app && mcpp build)            # exit 1; the same with --strict
warning: …/app/src/main.cpp: module 'acme.kit.extra' imported but not provided in this build
   Compiling acme.kit v0.1.0 (../kit)
   Compiling app v0.1.0 (.)
error: build failed in app v0.1.0 (.)
acme.kit.extra: error: failed to read compiled module: No such file or directory

No diagnostic about the manifest, with or without --strict: the second line replaces the first, acme.kit.extra is gone, and the first sign is a compiler error about a module file.

The same two keys with string values (for comparison; the packages need not exist)

[dependencies]
acme.kit       = "0.1.0"
acme.kit.extra = "0.1.0"
$ (cd app && mcpp build)            # exit 2
error: …/app/mcpp.toml:7:25: error: key path conflict

The documented spelling works, in either position, with and without --strict, and without a deprecation warning:

[dependencies]
"acme.kit"     = { path = "../kit" }
acme.kit.extra = { path = "../extra" }

Expected

  • A and B stop with the error the string form already gets (key path conflict, with the line and column), in both orders and regardless of --strict: an inline table is closed, so a later dotted key into it, or an inline table over a table that dotted keys defined, is the same conflict.
  • The error for a dependency table carries a help line with the spelling docs/05 gives: quote one of the two keys ("acme.kit" = …), and say that this quoted key is not the deprecated one.

Where we met it

mcpplibs/mwrap: the collection package mcpplibs.mwrap (one feature per library, so its dependency line is a table) next to a wrapper of its namespace such as mcpplibs.mwrap.libc (mcpplibs/mwrap#1). The quoted key is what we use there; the report is about what a project sees before it learns that.

Activity

  1. speak-agent commented on Dec 5, 2026

    @speak-agent
    Member

    Analysis, for the release after 2026.12.4.1.

    Cause. The manifest's TOML reader (modules/libs/src/toml.cppm, the key = value branch) does not treat an inline table as closed, so acme.kit.extra dives into the table acme.kit = { … } and becomes a field of it (case A); and it assigns a key that is already defined without refusing, so acme.kit = { … } replaces the table that acme.kit.extra defined (case B). With string values the dive fails, which is why that form already reports key path conflict.

    Decision: no TOML extension. Accepting both keys unquoted, even in dependency tables only, would make mcpp.toml a file other TOML readers refuse (editors, formatters, tomllib, CI scripts), a package's manifest unreadable by earlier mcpp releases, and give one dependency two spellings. The case is rare (a package and a package of its namespace in one table), mcpp add already writes the quoted key there, and an error with its remedy teaches the rule at once.

    Planned change.

    • An inline table is closed: a dotted key into one is key path conflict.
    • A key defined twice is an error that names both positions, in either order. A plain duplicate (a = 1 twice), which is read as the last today, is refused as Cargo refuses it, once the ecosystem's manifests are checked for it; if any use it, it is warned for one release first (docs/51).
    • In a dependency table the error carries a help: line with the spelling docs/05 gives ("acme.kit" = { path = "../kit" }) and says that this quoted key is not the deprecated one.
    • Tests: the reader's unit tests for both orders and both value kinds, the valid spellings unchanged; one e2e case for the help line. docs/05 and the CHANGELOG.

    The quoted-key deprecation is unchanged. quoted-dotted-dependency-key (docs/51, removed from 2027.2) applies only where the key can be written unquoted; the quoted key of a package beside its parent or child is its spelling, is not warned, and stays valid after 2027.2.

  2. speak-agent commented on Dec 6, 2026

    @speak-agent
    Member

    Fixed in 2026.12.6.1 (#1044).

    • An inline table is closed: a later dotted key into it, a key defined twice, and a key that is both a value and a table are refused with both keys and their lines, in either order and without --strict (SPEC-004 §17 item 3). Case A and case B of this report both stop at the manifest now.
    • In a dependency table the error is reported once and carries the help line: quote the key of the outer package ("acme.kit" = …); that quoted key is the canonical spelling, not the deprecated one. mcpp add writes the same form (§17 item 2).
    • A machine's config.toml that an earlier release wrote with a key defined twice is still read, by its later definition, with a warning naming the file and the key, so an upgrade does not stop on it.
    • Covered by the TOML and manifest unit tests and e2e 1186; 2026.12.6.1 and 2026.12.6.2 were checked in a clean xlings home.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions