What's wrong
Two naming cases pass kschema validate cleanly, yet the C# the generator emits for them doesn't compile.
a) Framework types aren't global::-qualified
MapType and the initialisers write System.Numerics.Vector3, System.Collections.Generic.List<…>, System.DateTime and so on (CSharpCodeGenerator.cs:639-651, :722-725). Inside namespace Game;, a schema class named System (a very common ECS name) makes System resolve to Game.System:
"classes": [
{ "name": "System", "members": [ { "name": "Priority", "type": { "TypeName": "Int" } } ] },
{ "name": "Transform", "members": [
{ "name": "Position", "type": { "TypeName": "Vector3" } },
{ "name": "Tags", "type": { "TypeName": "Array", "elementType": { "TypeName": "String" }, "container": "vector" } } ] }
],
"codeGenerators": [ { "name": "CS", "language": "csharp", "namespace": "Game", "outputPath": "out" } ]
This fails with CS0426: The type name 'Numerics' does not exist in the type 'System', and the same for Collections. By the same mechanism, a configured namespace such as Acme.System, or a class named ktsu, breaks the ktsu.Schema.Runtime.* references.
b) Member named after its enclosing type
GenerateClass never compares a member's name with the class name. Class Label with member Label: String emits public string Label { get; set; } inside public class Label, which fails with CS0542: member names cannot be the same as their enclosing type. The same applies to a semantic type named Value (the generator adds a Value property to it) and to an interface function named after its interface.
Why it matters
These are ordinary names. The schema validates cleanly, and the failure only appears when the consumer builds, pointing at generated code.
Suggested fix / acceptance criteria
- Prefix every framework and runtime type the C# generator emits with
global::, e.g. global::System.Numerics.Vector3 and global::ktsu.Schema.Runtime.….
- For (b), there is no C# escape, so report the collision in
Validate() (an Error, or a C#-generator-specific check before generation) with a message naming the class and member.
- Add tests that generate and compile: a schema with a class named
System that uses vector and list members, a namespace ending in .System, and a member/class name clash that is refused with a diagnostic.
What's wrong
Two naming cases pass
kschema validatecleanly, yet the C# the generator emits for them doesn't compile.a) Framework types aren't
global::-qualifiedMapTypeand the initialisers writeSystem.Numerics.Vector3,System.Collections.Generic.List<…>,System.DateTimeand so on (CSharpCodeGenerator.cs:639-651, :722-725). Insidenamespace Game;, a schema class namedSystem(a very common ECS name) makesSystemresolve toGame.System:This fails with
CS0426: The type name 'Numerics' does not exist in the type 'System', and the same forCollections. By the same mechanism, a configured namespace such asAcme.System, or a class namedktsu, breaks thektsu.Schema.Runtime.*references.b) Member named after its enclosing type
GenerateClassnever compares a member's name with the class name. ClassLabelwith memberLabel: Stringemitspublic string Label { get; set; }insidepublic class Label, which fails withCS0542: member names cannot be the same as their enclosing type. The same applies to a semantic type namedValue(the generator adds aValueproperty to it) and to an interface function named after its interface.Why it matters
These are ordinary names. The schema validates cleanly, and the failure only appears when the consumer builds, pointing at generated code.
Suggested fix / acceptance criteria
global::, e.g.global::System.Numerics.Vector3andglobal::ktsu.Schema.Runtime.….Validate()(an Error, or a C#-generator-specific check before generation) with a message naming the class and member.Systemthat uses vector and list members, a namespace ending in.System, and a member/class name clash that is refused with a diagnostic.