Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions changelog.d/csharp-reference-facet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- **The C# loader reads and enforces the reference facet** (`ref` on a `type: "attr"` entry of
a provider definition, `spec/metamodel-definitions.md`), matching the TypeScript loader: the
spec reader validates the facet and carries it to `AttrSchema.Ref`, the lookup is typed by the
target, a dotted value resolves `System.child` and `pkg::System.child`, a bare value is looked
for in the referrer's own containers first, and a value that names nothing
(`ERR_REF_UNRESOLVED`), the wrong kind of node (`ERR_REF_WRONG_KIND`) or a node of another
system (the facet's own code) is refused. A canonical value is the path the lookup walked, and
a value whose canonical spelling would not look up the same target is kept as written. The
registry manifest writes `ref` only on an attribute that has one. No definition file uses the
facet yet, so no registry, manifest or generated output changes. A provider's own code that is
not an `ErrorCode` member now keeps its spelling in `MetaError.ProviderCode` (`Code` stays
`ERR_UNKNOWN`; `CodeName` gives either). A parent-relative `@references` value
(`..::Address.id`) now resolves its owner instead of reading the `..` as one.

Upgrading: C# `ReferenceDescriptor` is now `(Attr, Facet)`. A provider that sets
`TypeDefinition.References` in code builds `new ReferenceDescriptor(attr, new ReferenceFacet(...))`.
`TargetType` and `ErrorCode` move onto `ReferenceFacet` (where `ErrorCode` is optional),
`TargetSubType` becomes the list `ReferenceFacet.TargetSubTypes`, and `DottedFieldPath` becomes
`ReferenceFacet.FieldPath`.
2 changes: 1 addition & 1 deletion server/csharp/MetaObjects.Cli/GenCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public static Outcome Run(
string? projectRoot = null,
string baseline = "default")
{
var loadErrors = load.Errors.Select(e => e.Code.ToString()).ToList();
var loadErrors = load.Errors.Select(e => e.CodeName).ToList();
if (loadErrors.Count > 0)
return new Outcome(loadErrors, null);

Expand Down
6 changes: 3 additions & 3 deletions server/csharp/MetaObjects.Cli/VerifyCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public static int RunRequirementGate(Options opts, bool requireImplementers, Tex
{
if (!loadFailureReported)
{
foreach (var e in load.Errors) output.WriteLine($" load error: {e.Code}: {e.Message}");
foreach (var e in load.Errors) output.WriteLine($" load error: {e.CodeName}: {e.Message}");
if (opts.Strict && load.Errors.Any(e => e.Code == ErrorCode.ERR_UNKNOWN_ATTR))
output.WriteLine($" hint: {UNKNOWN_ATTR_HINT}");
output.WriteLine("dotnet meta verify: FAILED (metadata did not load cleanly)");
Expand Down Expand Up @@ -435,7 +435,7 @@ private static Codegen.CodegenDrift.Result RunCodegenDrift(Options opts, List<st
{
Clean = false,
Error = "verify --codegen: metadata did not load cleanly (" +
string.Join("; ", load.Errors.Select(e => e.Code + ": " + e.Message)) + ").",
string.Join("; ", load.Errors.Select(e => e.CodeName + ": " + e.Message)) + ").",
};

var names = opts.Generators ?? [];
Expand Down Expand Up @@ -545,7 +545,7 @@ public static Outcome Run(
/// </summary>
public static Outcome Run(LoadResult load, string templatesRoot)
{
var loadErrors = load.Errors.Select(e => e.Code.ToString()).ToList();
var loadErrors = load.Errors.Select(e => e.CodeName).ToList();

var provider = new FilesystemProvider(templatesRoot);
var errors = new List<Drift>();
Expand Down
6 changes: 3 additions & 3 deletions server/csharp/MetaObjects.Codegen/CodegenCli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public static GenOutcome RunGen(
IReadOnlyList<string>? entities = null,
Func<GenConfig, GenConfig>? configure = null)
{
var loadErrors = load.Errors.Select(e => e.Code.ToString()).ToList();
var loadErrors = load.Errors.Select(e => e.CodeName).ToList();
if (loadErrors.Count > 0) return new GenOutcome(loadErrors, null);

var root = projectRoot ?? Directory.GetCurrentDirectory();
Expand Down Expand Up @@ -817,7 +817,7 @@ private static int RunGenCore(string[] rest, IReadOnlyList<IGenerator> declared,
genLoad = meta.Load(strict: true);
if (genLoad.Errors.Count > 0)
{
foreach (var e in genLoad.Errors) Console.Error.WriteLine($" load error: {e.Code}: {e.Message}");
foreach (var e in genLoad.Errors) Console.Error.WriteLine($" load error: {e.CodeName}: {e.Message}");
if (genLoad.Errors.Any(e => e.Code == ErrorCode.ERR_UNKNOWN_ATTR))
Console.Error.WriteLine($" hint: {GenStrictHint}");
Console.Error.WriteLine($"{GenCommandName}: FAILED (metadata did not load cleanly; --strict)");
Expand Down Expand Up @@ -1032,7 +1032,7 @@ private static int RunVerifyArgs(string[] rest, IReadOnlyList<IGenerator> declar
var load = meta.Load(strict: !a.Lax);
if (load.Errors.Count > 0)
{
foreach (var e in load.Errors) Console.Error.WriteLine($" load error: {e.Code}: {e.Message}");
foreach (var e in load.Errors) Console.Error.WriteLine($" load error: {e.CodeName}: {e.Message}");
Console.Error.WriteLine($"{VerifyCommandName}: FAILED (metadata did not load cleanly)");
return 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,14 @@ private static LoadOutcome LoadFixtureCore(

return new LoadOutcome(
result.Root,
result.Errors.Select(e => e.Code.ToString()).ToList(),
result.Errors.Select(e => e.CodeName).ToList(),
result.Warnings.ToList(),
envelopes,
warningEnvelopes);
}

private static ErrorEnvelopeRecord BuildEnvelope(MetaError err, string inputDir) =>
BuildEnvelopeFromSource(err.Code.ToString(), err.Envelope, inputDir) with { Message = err.Message };
BuildEnvelopeFromSource(err.CodeName, err.Envelope, inputDir) with { Message = err.Message };

private static ErrorEnvelopeRecord BuildWarningEnvelope(LoaderWarning w, string inputDir) =>
BuildEnvelopeFromSource(w.Code, w.Source, inputDir);
Expand Down
Loading
Loading