Repository navigation
Let two generators built on StuntGenerator run on one compilation - #359
Merged
Merged
Conversation
A project that uses Stunt.Of and a generator that configures a StuntGenerator of its own (Moq's MockGenerator) did not compile: both emitted Stunts.Generated.StuntRegistrations.Initialize (CS0111) and the ModuleInitializerAttribute polyfill (CS0101, CS0579), and they shared the registry key of CompiledStuntFactory, so a stunt and a mock of the same type replaced each other. The generator attribute now tells generators apart: - A generator with its own attribute appends a suffix made from the attribute's full name to StuntRegistrations, StuntDefinitions and the __RegisterStunt forwarders. The names of the default generator do not change. StuntClosure.DefinitionsTypeName and DefinitionMethods become instance members, so each closure reads its own definitions. - It passes that name to new CompiledStuntFactory.Register overloads, and the registry key includes it. A runtime creates its proxies with new CompiledStuntFactory(typeof(MockGeneratorAttribute)); the parameterless constructor creates plain stunts only. - The polyfill is a partial class without attributes, so the declarations of several generators merge. - [assembly: Stunt<T>] asks for a stunt, so a generator with its own generator attribute no longer reads it: it reads the attribute set with WithRegistrationAttribute, or none. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-authored-by: CodeAlta <noreply@codealta.io>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A project that uses
Stunt.Of<T>()and a generator that configures aStuntGeneratorof its own (Moq'sMockGenerator) did not compile with1.0.0-beta.4:CS0111: both generators emittedStunts.Generated.StuntRegistrations.Initialize.CS0101andCS0579: both emitted theModuleInitializerAttributepolyfill where the framework lacks it.CompiledStuntFactory, so a stunt and a mock of the same type in one assembly would replace each other.[assembly: Stunt<T>]made both generators generate a type.What changes
The generator attribute tells generators apart.
_Moq_MockGeneratorAttribute) toStuntRegistrations,StuntDefinitionsand the__RegisterStuntforwarders. The names of the default generator do not change.CompiledStuntFactory.Registeroverloads, and the registry key includes it. A runtime creates its proxies withnew CompiledStuntFactory(typeof(MockGeneratorAttribute)); the parameterless constructor creates plain stunts only.[assembly: Stunt<T>]asks for a stunt, so a generator with its own generator attribute no longer reads it. It reads the attribute set withWithRegistrationAttribute, or none.Breaking for extenders
CompiledStuntFactoryfor a generator with its own generator attribute must pass that attribute to the constructor, or its proxies are not found. Moq'sStaticMockFactoryneeds this change.StuntClosure.DefinitionsTypeNameandStuntClosure.DefinitionMethodsare instance members now.Tests
StuntGeneratorTests:RunsTwoGeneratorsOverOneCompilation,ClosesWrappersOfAnotherGeneratorFromReferencedAssembliesandModuleInitializerPolyfillsOfTwoGeneratorsMerge. The unit test project passes (407 tests).🤖 Generated with Claude Code
This pull request was created by CodeAlta.