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
26 changes: 26 additions & 0 deletions Schema.Cpp.Test/ExemplarInterfaceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public sealed class ExemplarInterfaceTests
#include <span>

#include "EntityId.gen.hpp"
#include "ErrorCode.gen.hpp"
#include "Position.gen.hpp"
#include "RigidBody.gen.hpp"
#include "Seconds.gen.hpp"
Expand Down Expand Up @@ -124,6 +125,31 @@ public void TheErrorTypeComesFromTheSchema()
Assert.Contains("holo::Result<holo::Handle<RigidBody>, ErrorCode>", code, StringComparison.Ordinal);
}

/// <summary>
/// The header includes the error enum it names, so it compiles on its own.
/// </summary>
/// <remarks>
/// The error type is the one named type a signature reaches without the schema's type
/// vocabulary naming it: every other name in a header arrives through <c>Enum</c>,
/// <c>Object</c> or <c>Interface</c> and takes its include along the way, while this one comes
/// off the schema root because a failure says the same thing everywhere. That asymmetry is how
/// it came to be emitted as a bare name with no include -- the header named
/// <c>Result&lt;T, ErrorCode&gt;</c> and declared nothing called <c>ErrorCode</c>, so it
/// compiled only where something else had already included the enum first.
/// <para>
/// Asserted on the include rather than on a compile, because a compile in this suite pulls in
/// the whole generated set and would pass on the neighbour's include -- which is exactly the
/// accident being tested for.
/// </para>
/// </remarks>
[TestMethod]
public void TheHeaderIncludesTheErrorEnumItNames()
{
string code = Generate()["IPhysicsWorld.gen.hpp"];

Assert.Contains("#include \"ErrorCode.gen.hpp\"", code, StringComparison.Ordinal);
}

/// <summary>
/// A target that has no fallible return is told which option to set, rather than handed a
/// header that will not compile.
Expand Down
6 changes: 5 additions & 1 deletion Schema.Cpp/CppTypeMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,11 @@ private TypeReference MapResult(SchemaTypes.Result result)
"A signature returns a Result, but the schema names no error type. Set the schema's error type to an enum it declares.");
}

outcome.TypeArguments.Add(new TypeReference(schema.ErrorType.ToString()));
// Through `Generated` rather than as a bare name, so the header carries the enum's
// include. It is the one named type a signature can reach without the schema's type
// vocabulary naming it -- the error comes from the schema root rather than from the
// return type -- which is exactly how it came to be the one that was missed.
outcome.TypeArguments.Add(Generated(schema.ErrorType.ToString()));
return outcome;
}

Expand Down