From 6e42967027d510bd2e0429cfa8be06c297dca179 Mon Sep 17 00:00:00 2001 From: Kinflou Date: Sun, 15 Nov 2026 06:27:27 +0800 Subject: [PATCH] compiler: conformance cases for own-schema paths (specification#11, part) A package's own schemas are reached only through package::, parent:: or self::; an absolute first segment is std or a dependency. New group imports: a bare path to an own schema, in each form of a use, is import::bare-own-schema-path; the relative forms, a dependency's and std's paths build; a path matching nothing is import::unresolved; a schema named like a dependency, and the reserved dependency names (std, package, parent, self), are refused. bounded's three uses of the package's own models schema say package::. Groups and the format cases stay with specification#11. --- compiler/cases/bounded.json | 6 +- compiler/cases/imports.json | 642 +++++++++++++++++++++++++++++++++ compiler/readme.md | 5 + compiler/src/bounded.cue | 6 +- compiler/src/imports.cue | 210 +++++++++++ specs/compiler.cue | 2 + specs/gen/compiler.schema.json | 8 + 7 files changed, 873 insertions(+), 6 deletions(-) create mode 100644 compiler/cases/imports.json create mode 100644 compiler/src/imports.cue diff --git a/compiler/cases/bounded.json b/compiler/cases/bounded.json index 41da32b..b417922 100644 --- a/compiler/cases/bounded.json +++ b/compiler/cases/bounded.json @@ -264,7 +264,7 @@ }, { "path": "src/api.ids", - "text": "use models::Blob\n\nprotocol Orders {\n function send(b: Blob);\n}\n" + "text": "use package::models::Blob\n\nprotocol Orders {\n function send(b: Blob);\n}\n" } ], "dependencies": [] @@ -295,7 +295,7 @@ }, { "path": "src/api.ids", - "text": "use models::Blob\n\n@unverified = \"orders carry the upload\"\nprotocol Orders {\n function send(b: Blob);\n}\n" + "text": "use package::models::Blob\n\n@unverified = \"orders carry the upload\"\nprotocol Orders {\n function send(b: Blob);\n}\n" } ], "dependencies": [] @@ -354,7 +354,7 @@ }, { "path": "src/api.ids", - "text": "use models::Blob\n\nprotocol Orders {\n function send(b: Blob);\n}\n" + "text": "use package::models::Blob\n\nprotocol Orders {\n function send(b: Blob);\n}\n" } ], "dependencies": [] diff --git a/compiler/cases/imports.json b/compiler/cases/imports.json new file mode 100644 index 0000000..952f8d7 --- /dev/null +++ b/compiler/cases/imports.json @@ -0,0 +1,642 @@ +{ + "$schema": "../../specs/gen/compiler.schema.json", + "group": "imports", + "cases": [ + { + "id": "imports/bare-own-item", + "description": "a bare path to an item of the package's own schema is an error", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\n", + "schemas": [ + { + "path": "src/models.ids", + "text": "struct Blob {\n size: u32\n}\n\nstruct Tag {\n id: u32\n}\n" + }, + { + "path": "src/api.ids", + "text": "use models::Blob\n\nstruct Upload {\n blob: Blob\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [ + { + "code": "import::bare-own-schema-path", + "severity": "error" + } + ] + } + }, + { + "id": "imports/bare-own-namespace", + "description": "a bare path to the package's own schema as a whole is an error", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\n", + "schemas": [ + { + "path": "src/models.ids", + "text": "struct Blob {\n size: u32\n}\n\nstruct Tag {\n id: u32\n}\n" + }, + { + "path": "src/api.ids", + "text": "use models\n\nstruct Upload {\n blob: Blob\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [ + { + "code": "import::bare-own-schema-path", + "severity": "error" + } + ] + } + }, + { + "id": "imports/bare-own-multi", + "description": "a bare path with {...} to the package's own schema is an error", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\n", + "schemas": [ + { + "path": "src/models.ids", + "text": "struct Blob {\n size: u32\n}\n\nstruct Tag {\n id: u32\n}\n" + }, + { + "path": "src/api.ids", + "text": "use models::{Blob, Tag}\n\nstruct Upload {\n blob: Blob\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [ + { + "code": "import::bare-own-schema-path", + "severity": "error" + } + ] + } + }, + { + "id": "imports/bare-own-glob", + "description": "a bare path with * to the package's own schema is an error", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\n", + "schemas": [ + { + "path": "src/models.ids", + "text": "struct Blob {\n size: u32\n}\n\nstruct Tag {\n id: u32\n}\n" + }, + { + "path": "src/api.ids", + "text": "use models::*\n\nstruct Upload {\n blob: Blob\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [ + { + "code": "import::bare-own-schema-path", + "severity": "error" + } + ] + } + }, + { + "id": "imports/bare-own-nested", + "description": "a bare path to a schema in a directory of the package is an error, whatever the importing schema's own place", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\n", + "schemas": [ + { + "path": "src/shapes/models.ids", + "text": "struct Blob {\n size: u32\n}\n\nstruct Tag {\n id: u32\n}\n" + }, + { + "path": "src/shapes/api.ids", + "text": "use shapes::models::Blob\n\nstruct Upload {\n blob: Blob\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [ + { + "code": "import::bare-own-schema-path", + "severity": "error" + } + ] + } + }, + { + "id": "imports/package-item", + "description": "package:: reaches an item of the package's own schema", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\n", + "schemas": [ + { + "path": "src/models.ids", + "text": "struct Blob {\n size: u32\n}\n\nstruct Tag {\n id: u32\n}\n" + }, + { + "path": "src/api.ids", + "text": "use package::models::Blob\n\nstruct Upload {\n blob: Blob\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "protocols": [], + "builds": true, + "diagnostics": [] + } + }, + { + "id": "imports/package-namespace", + "description": "package:: reaches the package's own schema as a whole", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\n", + "schemas": [ + { + "path": "src/models.ids", + "text": "struct Blob {\n size: u32\n}\n\nstruct Tag {\n id: u32\n}\n" + }, + { + "path": "src/api.ids", + "text": "use package::models\n\nstruct Upload {\n blob: models::Blob\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "protocols": [], + "builds": true, + "diagnostics": [] + } + }, + { + "id": "imports/package-multi", + "description": "package:: with {...} reaches several items of the package's own schema", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\n", + "schemas": [ + { + "path": "src/models.ids", + "text": "struct Blob {\n size: u32\n}\n\nstruct Tag {\n id: u32\n}\n" + }, + { + "path": "src/api.ids", + "text": "use package::models::{Blob, Tag}\n\nstruct Upload {\n blob: Blob\n tag: Tag\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "protocols": [], + "builds": true, + "diagnostics": [] + } + }, + { + "id": "imports/package-glob", + "description": "package:: with * reaches every item of the package's own schema", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\n", + "schemas": [ + { + "path": "src/models.ids", + "text": "struct Blob {\n size: u32\n}\n\nstruct Tag {\n id: u32\n}\n" + }, + { + "path": "src/api.ids", + "text": "use package::models::*\n\nstruct Upload {\n blob: Blob\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "protocols": [], + "builds": true, + "diagnostics": [] + } + }, + { + "id": "imports/package-nested", + "description": "package:: reaches a schema in a directory of the package from one beside it", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\n", + "schemas": [ + { + "path": "src/shapes/models.ids", + "text": "struct Blob {\n size: u32\n}\n\nstruct Tag {\n id: u32\n}\n" + }, + { + "path": "src/shapes/api.ids", + "text": "use package::shapes::models::Blob\n\nstruct Upload {\n blob: Blob\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "protocols": [], + "builds": true, + "diagnostics": [] + } + }, + { + "id": "imports/parent-item", + "description": "parent:: reaches a schema one level up from the importing schema's namespace", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\n", + "schemas": [ + { + "path": "src/shapes/models.ids", + "text": "struct Blob {\n size: u32\n}\n\nstruct Tag {\n id: u32\n}\n" + }, + { + "path": "src/shapes/api.ids", + "text": "use parent::models::Blob\n\nstruct Upload {\n blob: Blob\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "protocols": [], + "builds": true, + "diagnostics": [] + } + }, + { + "id": "imports/self-item", + "description": "self:: reaches a schema under the importing schema's own namespace", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "use self::models::Blob\n\nstruct Upload {\n blob: Blob\n}\n" + }, + { + "path": "src/api/models.ids", + "text": "struct Blob {\n size: u32\n}\n\nstruct Tag {\n id: u32\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "protocols": [], + "builds": true, + "diagnostics": [] + } + }, + { + "id": "imports/dependency-path", + "description": "a bare path whose first segment is a dependency reaches the dependency's schema", + "packages": [ + { + "name": "models", + "config": "congregation models\nspecification_version = 1\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "struct Blob {\n size: u32\n}\n\nstruct Tag {\n id: u32\n}\n" + } + ], + "dependencies": [] + }, + { + "name": "app", + "config": "congregation app\nspecification_version = 1\ndependencies = {\n models = {\n path = \"../models\"\n }\n}\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "use models::api::Blob\n\nstruct Upload {\n blob: Blob\n}\n" + } + ], + "dependencies": [ + { + "name": "models" + } + ] + } + ], + "build": "app", + "expect": { + "protocols": [], + "builds": true, + "diagnostics": [] + } + }, + { + "id": "imports/std-path", + "description": "a bare path whose first segment is std reaches the standard library's schema", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "use std::http::Request\n\nstruct Call {\n request: Request\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "protocols": [], + "builds": true, + "diagnostics": [] + } + }, + { + "id": "imports/unknown-first-segment", + "description": "a bare path that is neither a dependency, std nor one of the package's schemas is unresolved, not this error", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\n", + "schemas": [ + { + "path": "src/models.ids", + "text": "struct Blob {\n size: u32\n}\n\nstruct Tag {\n id: u32\n}\n" + }, + { + "path": "src/api.ids", + "text": "use modles::Blob\n\nstruct Upload {\n blob: Blob\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [ + { + "code": "import::unresolved", + "severity": "error" + } + ] + } + }, + { + "id": "imports/own-schema-named-like-dependency", + "description": "a package's own schema named like one of its dependencies is refused, so a first segment is never both", + "packages": [ + { + "name": "models", + "config": "congregation models\nspecification_version = 1\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "struct Blob {\n size: u32\n}\n\nstruct Tag {\n id: u32\n}\n" + } + ], + "dependencies": [] + }, + { + "name": "app", + "config": "congregation app\nspecification_version = 1\ndependencies = {\n models = {\n path = \"../models\"\n }\n}\n", + "schemas": [ + { + "path": "src/models.ids", + "text": "struct Blob {\n size: u32\n}\n\nstruct Tag {\n id: u32\n}\n" + } + ], + "dependencies": [ + { + "name": "models" + } + ] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [], + "error_contains": [ + "schema 'models.ids' is named like the dependency 'models'" + ] + } + }, + { + "id": "imports/dependency-named-std", + "description": "std can't be a dependency's name", + "packages": [ + { + "name": "std", + "config": "congregation std\nspecification_version = 1\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "struct Blob {\n size: u32\n}\n\nstruct Tag {\n id: u32\n}\n" + } + ], + "dependencies": [] + }, + { + "name": "app", + "config": "congregation app\nspecification_version = 1\ndependencies = {\n std = {\n path = \"../std\"\n }\n}\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "struct Upload {\n blob: Blob\n}\n" + } + ], + "dependencies": [ + { + "name": "std" + } + ] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [], + "error_contains": [ + "reserved" + ] + } + }, + { + "id": "imports/dependency-named-package", + "description": "package can't be a dependency's name", + "packages": [ + { + "name": "package", + "config": "congregation package\nspecification_version = 1\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "struct Blob {\n size: u32\n}\n\nstruct Tag {\n id: u32\n}\n" + } + ], + "dependencies": [] + }, + { + "name": "app", + "config": "congregation app\nspecification_version = 1\ndependencies = {\n package = {\n path = \"../package\"\n }\n}\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "struct Upload {\n blob: Blob\n}\n" + } + ], + "dependencies": [ + { + "name": "package" + } + ] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [], + "error_contains": [ + "reserved" + ] + } + }, + { + "id": "imports/dependency-named-parent", + "description": "parent can't be a dependency's name", + "packages": [ + { + "name": "parent", + "config": "congregation parent\nspecification_version = 1\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "struct Blob {\n size: u32\n}\n\nstruct Tag {\n id: u32\n}\n" + } + ], + "dependencies": [] + }, + { + "name": "app", + "config": "congregation app\nspecification_version = 1\ndependencies = {\n parent = {\n path = \"../parent\"\n }\n}\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "struct Upload {\n blob: Blob\n}\n" + } + ], + "dependencies": [ + { + "name": "parent" + } + ] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [], + "error_contains": [ + "reserved" + ] + } + }, + { + "id": "imports/dependency-named-self", + "description": "self can't be a dependency's name", + "packages": [ + { + "name": "self", + "config": "congregation self\nspecification_version = 1\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "struct Blob {\n size: u32\n}\n\nstruct Tag {\n id: u32\n}\n" + } + ], + "dependencies": [] + }, + { + "name": "app", + "config": "congregation app\nspecification_version = 1\ndependencies = {\n self = {\n path = \"../self\"\n }\n}\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "struct Upload {\n blob: Blob\n}\n" + } + ], + "dependencies": [ + { + "name": "self" + } + ] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [], + "error_contains": [ + "reserved" + ] + } + } + ] +} diff --git a/compiler/readme.md b/compiler/readme.md index 0045c42..088b9f8 100644 --- a/compiler/readme.md +++ b/compiler/readme.md @@ -135,6 +135,7 @@ cases with `dependencies`, which are in `acceptance` and `chain`. | `package` | `unverified` in `config.idp`: the keyed and plain forms covering what a protocol takes from the package's settings; a protocol with its own `@handshake` not covered; `unverified::wrong-scope` for `bounded_size`; a guarantee no protocol gives up through it; the gate; a marker adding `bounded_size` | | `bounded` | `bounded_size`: a string or list without a maximum, a type that contains itself without `@max_depth`, a type from another schema of the package that holds one, each unmarked (an error) and marked (given up), and the bounded variants | | `acceptance` | a dependency's unverified protocols accepted under it in `config.idp`: not at all, exactly, for less, for more; the reasons the consumer is shown; the dependency judged by its own package | +| `imports` | where a `use` path starts: a package's own schemas only through `package::`, `parent::` or `self::` (a bare path to one is `import::bare-own-schema-path`, in each form of a `use`), a dependency's and `std`'s paths as they were, a path matching nothing (`import::unresolved`), a schema named like a dependency, and the names a dependency can't have | | `chain` | three packages, `c` depending on `b` depending on `a`: a type holding `a`'s unbounded value, used in `c`; and the acceptance resolving `b` asks for `a`'s protocols too | A case's `description` says what it shows. Each rule has a passing and a @@ -143,6 +144,10 @@ failing variant. ### To come Cases for rules core doesn't implement yet, which go in when it does: +a `group` on a dependency's entry and the same package regrouped, and a kind of case for +formatting imports ( +[specification#11](https://github.com/ComlineProject/specification/issues/11), +after core#284), acknowledgements at the inner scopes (function, argument, field and type), an outer scope covering an inner one, `strict`, pinning an acceptance to a chain of packages and its invalidation, and failing closed. diff --git a/compiler/src/bounded.cue b/compiler/src/bounded.cue index 0449776..98e6333 100644 --- a/compiler/src/bounded.cue +++ b/compiler/src/bounded.cue @@ -153,7 +153,7 @@ groups: bounded: { schemas: { models: _models api: """ - use models::Blob + use package::models::Blob protocol Orders { function send(b: Blob); @@ -171,7 +171,7 @@ groups: bounded: { schemas: { models: _models api: """ - use models::Blob + use package::models::Blob @unverified = "orders carry the upload" protocol Orders { @@ -205,7 +205,7 @@ groups: bounded: { } """ api: """ - use models::Blob + use package::models::Blob protocol Orders { function send(b: Blob); diff --git a/compiler/src/imports.cue b/compiler/src/imports.cue new file mode 100644 index 0000000..aaa62cb --- /dev/null +++ b/compiler/src/imports.cue @@ -0,0 +1,210 @@ +package cases + +// Where a `use` path starts. Within a package, its own schemas are reached +// only through a relative path: `package::` (from the package's root), +// `parent::` (one level up) or `self::` (the current namespace). An absolute +// first segment always means `std` or a dependency, so a bare path to one of +// the package's own schemas is an error, with a fix that writes `package::` +// in front of it (`import::bare-own-schema-path`). A path that matches +// nothing is `import::unresolved`, as it was. Rule and rollout: +// https://comlineproject.github.io/docs/proposals/use-paths-and-groups/relative-use/ +// +// A package's own schema named like a dependency or `std` is refused outright +// (the shadowing guard), and `std`, `package`, `parent` and `self` can't be a +// dependency's name. Neither error has a code: the cases say what the message +// contains, as the acceptance cases do. + +_impModels: """ + struct Blob { + size: u32 + } + + struct Tag { + id: u32 + } + """ + +// A schema using `Blob`, whichever way `use` brought it in. +_impUsesBlob: """ + struct Upload { + blob: Blob + } + """ + +groups: imports: { + // A bare path to the package's own schema, in each form of a `use`. + "bare-own-item": { + about: "a bare path to an item of the package's own schema is an error" + packages: app: schemas: {models: _impModels, api: "use models::Blob\n\n" + _impUsesBlob} + build: "app" + expect: {builds: false, errors: ["import::bare-own-schema-path"]} + } + "bare-own-namespace": { + about: "a bare path to the package's own schema as a whole is an error" + packages: app: schemas: {models: _impModels, api: "use models\n\n" + _impUsesBlob} + build: "app" + expect: {builds: false, errors: ["import::bare-own-schema-path"]} + } + "bare-own-multi": { + about: "a bare path with {...} to the package's own schema is an error" + packages: app: schemas: {models: _impModels, api: "use models::{Blob, Tag}\n\n" + _impUsesBlob} + build: "app" + expect: {builds: false, errors: ["import::bare-own-schema-path"]} + } + "bare-own-glob": { + about: "a bare path with * to the package's own schema is an error" + packages: app: schemas: {models: _impModels, api: "use models::*\n\n" + _impUsesBlob} + build: "app" + expect: {builds: false, errors: ["import::bare-own-schema-path"]} + } + "bare-own-nested": { + about: "a bare path to a schema in a directory of the package is an error, whatever the importing schema's own place" + packages: app: schemas: { + "shapes/models": _impModels + "shapes/api": "use shapes::models::Blob\n\n" + _impUsesBlob + } + build: "app" + expect: {builds: false, errors: ["import::bare-own-schema-path"]} + } + + // The same schemas through the relative forms, which build. + "package-item": { + about: "package:: reaches an item of the package's own schema" + packages: app: schemas: {models: _impModels, api: "use package::models::Blob\n\n" + _impUsesBlob} + build: "app" + expect: {builds: true, protocols: {}} + } + "package-namespace": { + about: "package:: reaches the package's own schema as a whole" + packages: app: schemas: {models: _impModels, api: "use package::models\n\nstruct Upload {\n blob: models::Blob\n}"} + build: "app" + expect: {builds: true, protocols: {}} + } + "package-multi": { + about: "package:: with {...} reaches several items of the package's own schema" + packages: app: schemas: {models: _impModels, api: "use package::models::{Blob, Tag}\n\nstruct Upload {\n blob: Blob\n tag: Tag\n}"} + build: "app" + expect: {builds: true, protocols: {}} + } + "package-glob": { + about: "package:: with * reaches every item of the package's own schema" + packages: app: schemas: {models: _impModels, api: "use package::models::*\n\n" + _impUsesBlob} + build: "app" + expect: {builds: true, protocols: {}} + } + "package-nested": { + about: "package:: reaches a schema in a directory of the package from one beside it" + packages: app: schemas: { + "shapes/models": _impModels + "shapes/api": "use package::shapes::models::Blob\n\n" + _impUsesBlob + } + build: "app" + expect: {builds: true, protocols: {}} + } + "parent-item": { + about: "parent:: reaches a schema one level up from the importing schema's namespace" + packages: app: schemas: { + "shapes/models": _impModels + "shapes/api": "use parent::models::Blob\n\n" + _impUsesBlob + } + build: "app" + expect: {builds: true, protocols: {}} + } + "self-item": { + about: "self:: reaches a schema under the importing schema's own namespace" + packages: app: schemas: { + "api": "use self::models::Blob\n\n" + _impUsesBlob + "api/models": _impModels + } + build: "app" + expect: {builds: true, protocols: {}} + } + + // A first segment that is not the package's: a dependency, and `std`. + "dependency-path": { + about: "a bare path whose first segment is a dependency reaches the dependency's schema" + packages: { + models: schemas: api: _impModels + app: { + schemas: api: "use models::api::Blob\n\n" + _impUsesBlob + dependencies: models: {} + } + } + build: "app" + expect: {builds: true, protocols: {}} + } + "std-path": { + about: "a bare path whose first segment is std reaches the standard library's schema" + packages: app: schemas: api: "use std::http::Request\n\nstruct Call {\n request: Request\n}" + build: "app" + expect: {builds: true, protocols: {}} + } + "unknown-first-segment": { + about: "a bare path that is neither a dependency, std nor one of the package's schemas is unresolved, not this error" + packages: app: schemas: {models: _impModels, api: "use modles::Blob\n\n" + _impUsesBlob} + build: "app" + expect: {builds: false, errors: ["import::unresolved"]} + } + + // What keeps a first segment from meaning two things. + "own-schema-named-like-dependency": { + about: "a package's own schema named like one of its dependencies is refused, so a first segment is never both" + packages: { + models: schemas: api: _impModels + app: { + schemas: models: _impModels + dependencies: models: {} + } + } + build: "app" + expect: {builds: false, error_contains: ["schema 'models.ids' is named like the dependency 'models'"]} + } + "dependency-named-std": { + about: "std can't be a dependency's name" + packages: { + std: schemas: api: _impModels + app: { + schemas: api: _impUsesBlob + dependencies: std: {} + } + } + build: "app" + expect: {builds: false, error_contains: ["reserved"]} + } + "dependency-named-package": { + about: "package can't be a dependency's name" + packages: { + package: schemas: api: _impModels + app: { + schemas: api: _impUsesBlob + dependencies: package: {} + } + } + build: "app" + expect: {builds: false, error_contains: ["reserved"]} + } + "dependency-named-parent": { + about: "parent can't be a dependency's name" + packages: { + parent: schemas: api: _impModels + app: { + schemas: api: _impUsesBlob + dependencies: parent: {} + } + } + build: "app" + expect: {builds: false, error_contains: ["reserved"]} + } + "dependency-named-self": { + about: "self can't be a dependency's name" + packages: { + self: schemas: api: _impModels + app: { + schemas: api: _impUsesBlob + dependencies: self: {} + } + } + build: "app" + expect: {builds: false, error_contains: ["reserved"]} + } +} diff --git a/specs/compiler.cue b/specs/compiler.cue index 9c7a736..e17be4d 100644 --- a/specs/compiler.cue +++ b/specs/compiler.cue @@ -104,6 +104,8 @@ import "github.com/comlineproject/specification/catalog" close({code!: "bounds::unbounded", severity!: "error"}), close({code!: "bounds::unbounded-depth", severity!: "error"}), close({code!: "settings::forbidden", severity!: "error"}), + close({code!: "import::bare-own-schema-path", severity!: "error"}), + close({code!: "import::unresolved", severity!: "error"}), ]) #CompilerWarning: or([ diff --git a/specs/gen/compiler.schema.json b/specs/gen/compiler.schema.json index 5613bbd..dae970a 100644 --- a/specs/gen/compiler.schema.json +++ b/specs/gen/compiler.schema.json @@ -112,6 +112,14 @@ { "code": "settings::forbidden", "severity": "error" + }, + { + "code": "import::bare-own-schema-path", + "severity": "error" + }, + { + "code": "import::unresolved", + "severity": "error" } ] },