Fix property lowering (static/indexer/set-only) in MSTest.AotReflection.SourceGeneration#9077
Conversation
…t.AotReflection.SourceGeneration The generated MSTestReflectionMetadata registry emitted invalid C# for some otherwise-valid [TestClass] shapes: - static properties produced ((T)instance).Prop (CS0176) - indexer properties produced ((T)instance).this[] (garbage) - set-only / non-readable properties emitted an unconditional getter Now static members are accessed through the type name, indexers are skipped (they cannot be modeled by the name-based Get/Set delegate shape), and the Get delegate throws when there is no accessible getter. Adds IsStatic and HasGettableValue to TestPropertyModel and three covering tests. Part of #1837. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes C# emission bugs in the MSTest.AotReflection.SourceGeneration generator so the generated MSTestReflectionMetadata.Registry.g.cs compiles for additional valid [TestClass] shapes (static properties, indexers, and set-only properties), improving robustness of the AOT reflection-metadata registry work for #1837.
Changes:
- Emit correct property access for static properties (type-qualified access) and correct setter targets for both static/instance properties.
- Skip indexer properties during model building so the registry doesn’t emit invalid “
this[...]” access. - For non-readable properties, emit a throwing
Getdelegate instead of referencing a missing/inaccessible getter, and extendTestPropertyModelwithIsStatic+HasGettableValueto support this.
Show a summary per file
| File | Description |
|---|---|
| test/UnitTests/MSTest.AotReflection.SourceGeneration.UnitTests/MSTestReflectionMetadataGeneratorTests.cs | Adds unit tests covering static property access, indexer skipping, and set-only property getter behavior. |
| src/Analyzers/MSTest.AotReflection.SourceGeneration/Model/TestClassModel.cs | Extends TestPropertyModel with IsStatic and HasGettableValue so codegen can decide correct access patterns. |
| src/Analyzers/MSTest.AotReflection.SourceGeneration/Generators/TestClassModelBuilder.cs | Filters out indexers and computes IsStatic/HasGettableValue for properties during model creation. |
| src/Analyzers/MSTest.AotReflection.SourceGeneration/Generators/MetadataRegistryEmitter.cs | Adjusts property Get/Set emission to handle static properties and set-only properties safely. |
Copilot's findings
- Files reviewed: 4/4 changed files
- Comments generated: 0
This comment has been minimized.
This comment has been minimized.
…ring (#9078) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
🧪 Test quality grade — PR #90774 new test methods graded across 1 file. 3 earn an A and 1 earns a B. Assertion variety and naming are strong throughout; the single B is caused solely by a slightly long body driven by the multi-step Roslyn driver setup, not by any weakness in what is verified.
This advisory comment was generated automatically. Grades are heuristic
|
The
MSTest.AotReflection.SourceGenerationregistry emitted invalid C# for some otherwise-valid[TestClass]shapes, which would block the registry from compiling once it is consumed:((T)instance).Prop(CS0176 — cannot access a static member through an instance),((T)instance).this[](garbage),Fix
T.Prop).Get/Setdelegate shape).Getdelegate throws when there is no accessible getter, instead of referencing one that does not exist.IsStaticandHasGettableValuetoTestPropertyModel.Tests
Three new tests (static access, indexer skip, set-only getter) plus existing coverage; 66/66 generator unit tests pass.
Part of #1837.