leancodepl / leancodepl/corelibrary
Typed identifiers generated in global namespace fail to compile
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 30
- Forks
- 4
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 3
Description
When typed id is placed in the global namespace, the project with generated code fails to compile with rather unhelpful build report.
using LeanCode.DomainModels.Ids;
// note no namespace declaration
[TypedId(TypedIdFormat.RawGuid)]
public readonly partial record struct Id;
results with
Restore complete (0.5s)
Example failed with 7 error(s) (0.4s)
/home/doktornauk/example/Example/src/obj/Debug/net9.0/LeanCode.DomainModels.Generators/LeanCode.DomainModels.Generators.TypedIdGenerator/Id.g.cs(3,11): error CS1001: Identifier expected
/home/doktornauk/example/Example/src/obj/Debug/net9.0/LeanCode.DomainModels.Generators/LeanCode.DomainModels.Generators.TypedIdGenerator/Id.g.cs(3,11): error CS1514: { expected
/home/doktornauk/example/Example/src/obj/Debug/net9.0/LeanCode.DomainModels.Generators/LeanCode.DomainModels.Generators.TypedIdGenerator/Id.g.cs(3,12): error CS0116: A namespace cannot directly contain members such as fields, methods or statements
/home/doktornauk/example/Example/src/obj/Debug/net9.0/LeanCode.DomainModels.Generators/LeanCode.DomainModels.Generators.TypedIdGenerator/Id.g.cs(3,28): error CS1001: Identifier expected
/home/doktornauk/example/Example/src/obj/Debug/net9.0/LeanCode.DomainModels.Generators/LeanCode.DomainModels.Generators.TypedIdGenerator/Id.g.cs(3,28): error CS1514: { expected
/home/doktornauk/example/Example/src/obj/Debug/net9.0/LeanCode.DomainModels.Generators/LeanCode.DomainModels.Generators.TypedIdGenerator/Id.g.cs(4,1): error CS1022: Type or namespace definition, or end-of-file expected
/home/doktornauk/example/Example/src/obj/Debug/net9.0/LeanCode.DomainModels.Generators/LeanCode.DomainModels.Generators.TypedIdGenerator/Id.g.cs(77,2): error CS1513: } expected
Build failed with 7 error(s) in 1.1s
This result comes from using ISymbol.ContainingNamespace.ToDisplayString() here, which resolves to <global namespace> for the global namespace, which is not a valid identifier in C# code.
We should either properly support identifiers in the global namespace or emit a diagnostic report instead of non-compiling code (preferably maybe?).
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/Domain/LeanCode.DomainModels.Generators/TypedIdGenerator.cs around the use of ISymbol.ContainingNamespace.ToDisplayString(). Reproduce the global-namespace TypedId example and build it to confirm the generated Id.g.cs failure. Done means global-namespace identifiers are either supported without compilation errors or a clear diagnostic is emitted instead of non-compiling generated code.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100