From afaec30f36db4d34d350e13a28fe8a2edae0310e Mon Sep 17 00:00:00 2001 From: hatayama Date: Sat, 28 Nov 2026 20:17:52 +0900 Subject: [PATCH 1/4] refactor: bind an extension method of a non-public class through typeof The accessor of an extension method of a non-public class found the class at bind time with Type.GetType(", ", true). Every supported Editor runs on Mono, which does not check type access on the ldtoken of a top-level internal class from the shim assembly (the shim compiles against publicized references), so typeof binds there as well: with typeof forced, every extension-call E2E test stayed Patched and returned the edited value. On a runtime that did check it, the bind would throw in __BindAccessors before any patch is applied. ADR 0010 already reopens Mono-only behavior when the Editor moves to CoreCLR. - AccessorEntry.EmitBindStatement always names the declaring class through typeof and no longer takes the target assembly; the reason is recorded on it. - Remove ExtensionClassNameBind.AssemblyQualifiedClassName. - Remove the target-assembly constructor parameter and property of ShimTypeBuilder, and its pass-through in OrdinaryMethodShimTypes, PropertyGetterEmitter.EmitPropertyGetterShim / EnsureShimType, and the setter and indexer emitters, which only forwarded it to the builder. - What the accessor may bind is unchanged: TryGetVisibilityFailure still allows the class only for an extension method that IsCompiledIn proves and FindRejectReasonOrNull checks. - Worker tests assert typeof(global::) instead of the Type.GetType string, and their descriptions say so. --- .../TransformWorkerAddedMemberAccessTests.cs | 66 +++++++++---------- ...mWorkerNonPublicClassExtensionCallTests.cs | 19 +++--- .../TransformWorker~/AccessorEntry.cs | 35 ++++------ .../ExtensionClassNameBind.cs | 15 ----- .../IndexerAccessorEmitter.cs | 3 +- .../OrdinaryMethodShimTypes.cs | 3 +- .../TransformWorker~/PropertyGetterEmitter.cs | 15 ++--- .../TransformWorker~/PropertySetterEmitter.cs | 3 +- .../TransformWorker~/ShimTypeBuilder.cs | 10 +-- 9 files changed, 66 insertions(+), 103 deletions(-) diff --git a/Assets/Tests/Editor/HotReload/TransformWorkerAddedMemberAccessTests.cs b/Assets/Tests/Editor/HotReload/TransformWorkerAddedMemberAccessTests.cs index fdef26b8fe..5eda684f00 100644 --- a/Assets/Tests/Editor/HotReload/TransformWorkerAddedMemberAccessTests.cs +++ b/Assets/Tests/Editor/HotReload/TransformWorkerAddedMemberAccessTests.cs @@ -558,39 +558,39 @@ public async Task AddedMethod_UnsubscribingAMethodGroup_DoesNotSuggestALambda() /// /// What: a lambda that reads a private field and calls, in reduced form (x.M()), an - /// internal extension method of an internal class is an entry whose accessor finds the - /// class by name, because the class is not public. + /// internal extension method of an internal class is an entry whose accessor names the + /// class through typeof, although the class is not public. /// [Test] - public async Task ExtensionCall_ClosureReadingPrivateFieldAndCallingInternalExtension_BindsTheClassByName() + public async Task ExtensionCall_ClosureReadingPrivateFieldAndCallingInternalExtension_BindsTheClassThroughTypeof() { TransformWorkerClientResult result = await RunExtensionCallHostEditAsync("4101", "4102"); AssertEntryAndNotSkipped(result, "ClosureReadsPrivateFieldAndCallsInternalExtension"); - AssertBindsByName(result, InternalExtensionClassName, "Twice", "typeof(int), typeof(int)"); + AssertBindsThroughTypeof(result, InternalExtensionClassName, "Twice", "typeof(int), typeof(int)"); } /// /// What: a lambda whose only inaccessible use is an internal extension method of an - /// internal class called in reduced form is an entry whose accessor finds the class by name. + /// internal class called in reduced form is an entry whose accessor names the class through typeof. /// [Test] - public async Task ExtensionCall_ClosureCallingOnlyInternalExtension_BindsTheClassByName() + public async Task ExtensionCall_ClosureCallingOnlyInternalExtension_BindsTheClassThroughTypeof() { TransformWorkerClientResult result = await RunExtensionCallHostEditAsync("4201", "4202"); AssertEntryAndNotSkipped(result, "ClosureCallsOnlyInternalExtension"); - AssertBindsByName(result, InternalExtensionClassName, "Twice", "typeof(int), typeof(int)"); + AssertBindsThroughTypeof(result, InternalExtensionClassName, "Twice", "typeof(int), typeof(int)"); } /// /// What: an async method that calls an internal extension method of an internal class in - /// reduced form is an entry whose accessor finds the class by name. + /// reduced form is an entry whose accessor names the class through typeof. /// [Test] - public async Task ExtensionCall_AsyncMethodCallingInternalExtension_BindsTheClassByName() + public async Task ExtensionCall_AsyncMethodCallingInternalExtension_BindsTheClassThroughTypeof() { TransformWorkerClientResult result = await RunExtensionCallHostEditAsync("4301", "4302"); AssertEntryAndNotSkipped(result, "AsyncCallsInternalExtension"); - AssertBindsByName(result, InternalExtensionClassName, "Twice", "typeof(int), typeof(int)"); + AssertBindsThroughTypeof(result, InternalExtensionClassName, "Twice", "typeof(int), typeof(int)"); } /// @@ -607,15 +607,15 @@ public async Task ExtensionCall_OwnStatementCallingInternalExtension_IsAnEntry() /// /// What: a lambda that calls an internal extension method in static form through its - /// internal class is an entry: the accessor call replaces the whole call, so the shim never - /// names the class, and the accessor finds it by name. + /// internal class is an entry: the accessor call replaces the whole call, so only the + /// accessor's bind names the class, through typeof. /// [Test] - public async Task ExtensionCall_ClosureNamingInternalExtensionClass_BindsTheClassByName() + public async Task ExtensionCall_ClosureNamingInternalExtensionClass_BindsTheClassThroughTypeof() { TransformWorkerClientResult result = await RunExtensionCallHostEditAsync("4501", "4502"); AssertEntryAndNotSkipped(result, "ClosureCallsInternalExtensionInStaticForm"); - AssertBindsByName(result, InternalExtensionClassName, "Twice", "typeof(int), typeof(int)"); + AssertBindsThroughTypeof(result, InternalExtensionClassName, "Twice", "typeof(int), typeof(int)"); } /// @@ -660,17 +660,17 @@ public async Task ExtensionCall_ClosureHoldingPrivateMethodGroup_KeepsWrapperHin /// /// What: a lambda that calls, in reduced form, a public extension method of an internal - /// class declared in the edited file is an entry whose accessor finds the class by name. + /// class declared in the edited file is an entry whose accessor names the class through typeof. /// The edited and compiled copies of the class both offer the method, so the call binds /// ambiguously; the accessor still binds the method the source calls, also while a public /// class in another file declares an extension of the same name. /// [Test] - public async Task ExtensionCall_ClosureCallingPublicExtensionOfInternalClassInEditedFile_BindsTheClassByName() + public async Task ExtensionCall_ClosureCallingPublicExtensionOfInternalClassInEditedFile_BindsTheClassThroughTypeof() { TransformWorkerClientResult result = await RunExtensionCallHostEditAsync("5101", "5102"); AssertEntryAndNotSkipped(result, "ClosureCallsPublicExtensionOfInternalClass"); - AssertBindsByName(result, InternalClassExtensionClassName, "Thrice", "typeof(int), typeof(int)"); + AssertBindsThroughTypeof(result, InternalClassExtensionClassName, "Thrice", "typeof(int), typeof(int)"); } /// @@ -692,11 +692,11 @@ public async Task ExtensionCall_ClosureCallingSameNamedExtensionOfSecondClass_Is /// name. /// [Test] - public async Task ExtensionCall_AsyncMethodCallingPublicExtensionOfInternalClassInEditedFile_BindsTheClassByName() + public async Task ExtensionCall_AsyncMethodCallingPublicExtensionOfInternalClassInEditedFile_BindsTheClassThroughTypeof() { TransformWorkerClientResult result = await RunExtensionCallHostEditAsync("5201", "5202"); AssertEntryAndNotSkipped(result, "AsyncCallsPublicExtensionOfInternalClass"); - AssertBindsByName(result, InternalClassExtensionClassName, "Thrice", "typeof(int), typeof(int)"); + AssertBindsThroughTypeof(result, InternalClassExtensionClassName, "Thrice", "typeof(int), typeof(int)"); } /// @@ -727,7 +727,7 @@ public async Task ExtensionCall_ClosureCallingOverloadedExtensionOfInternalClass { TransformWorkerClientResult result = await RunExtensionCallHostEditAsync("5401", "5402"); AssertEntryAndNotSkipped(result, "ClosureCallsOverloadedExtensionOfInternalClass"); - AssertBindsByName(result, InternalClassExtensionClassName, "Step", "typeof(int), typeof(int)"); + AssertBindsThroughTypeof(result, InternalClassExtensionClassName, "Step", "typeof(int), typeof(int)"); AssertShimDoesNotContain(result, "\"Step\", new global::System.Type[]{typeof(int), typeof(string)}"); } @@ -741,17 +741,17 @@ public async Task ExtensionCall_ClosureCallingBetterOverloadOfExtensionOfInterna { TransformWorkerClientResult result = await RunExtensionCallHostEditAsync("5501", "5502"); AssertEntryAndNotSkipped(result, "ClosureCallsBetterOverloadOfExtensionOfInternalClass"); - AssertBindsByName(result, InternalClassExtensionClassName, "Pick", "typeof(int), typeof(int)"); + AssertBindsThroughTypeof(result, InternalClassExtensionClassName, "Pick", "typeof(int), typeof(int)"); AssertShimDoesNotContain(result, "\"Pick\", new global::System.Type[]{typeof(int), typeof(long)}"); } /// /// What: when the same edit makes the internal extension class public and changes a lambda - /// that calls it, the lambda is an entry whose accessor still finds the class by name, + /// that calls it, the lambda is an entry whose accessor still names the class through typeof, /// because the running code calls the compiled class, which is still internal. /// [Test] - public async Task ExtensionCall_ClosureCallingExtensionOfClassMadePublicInSameEdit_BindsTheClassByName() + public async Task ExtensionCall_ClosureCallingExtensionOfClassMadePublicInSameEdit_BindsTheClassThroughTypeof() { string fixturePath = ResolveTestSourcePath("HotReloadExtensionCallFixtures.cs"); string onDisk = File.ReadAllText(fixturePath); @@ -770,7 +770,7 @@ public async Task ExtensionCall_ClosureCallingExtensionOfClassMadePublicInSameEd snapshotSource: onDisk); AssertEntryAndNotSkipped(result, "ClosureCallsPublicExtensionOfInternalClass"); - AssertBindsByName(result, InternalClassExtensionClassName, "Thrice", "typeof(int), typeof(int)"); + AssertBindsThroughTypeof(result, InternalClassExtensionClassName, "Thrice", "typeof(int), typeof(int)"); } /// @@ -800,10 +800,10 @@ public async Task ExtensionCall_ClosureCallingPublicExtension_IsAnEntry() /// /// What: a method added in this reload that calls an internal extension method of an internal - /// class in reduced form is added, and its accessor finds the class by name. + /// class in reduced form is added, and its accessor names the class through typeof. /// [Test] - public async Task ExtensionCall_AddedMethodCallingInternalExtension_BindsTheClassByName() + public async Task ExtensionCall_AddedMethodCallingInternalExtension_BindsTheClassThroughTypeof() { string fixturePath = ResolveTestSourcePath("HotReloadExtensionCallFixtures.cs"); string onDisk = File.ReadAllText(fixturePath); @@ -821,16 +821,16 @@ public async Task ExtensionCall_AddedMethodCallingInternalExtension_BindsTheClas snapshotSource: onDisk); AssertAddedAndNotSkipped(result, "AddedCallsInternalExtension"); - AssertBindsByName(result, InternalExtensionClassName, "Twice", "typeof(int), typeof(int)"); + AssertBindsThroughTypeof(result, InternalExtensionClassName, "Twice", "typeof(int), typeof(int)"); } /// /// What: when the same edit makes an internal class public and changes a lambda that calls an - /// internal extension method of it, the accessor still finds the class by name, because the + /// internal extension method of it, the accessor still names the class through typeof, because the /// running code calls the compiled class, which is still internal. /// [Test] - public async Task ExtensionCall_ClosureCallingInternalExtensionOfClassMadePublicInSameEdit_BindsTheClassByName() + public async Task ExtensionCall_ClosureCallingInternalExtensionOfClassMadePublicInSameEdit_BindsTheClassThroughTypeof() { TransformWorkerClientResult result = await RunExtensionCallHostCustomEditAsync(onDisk => { @@ -846,7 +846,7 @@ public async Task ExtensionCall_ClosureCallingInternalExtensionOfClassMadePublic }); AssertEntryAndNotSkipped(result, "ClosureReadsPrivateFieldAndCallsInternalExtension"); - AssertBindsByName(result, InternalExtensionClassName, "Twice", "typeof(int), typeof(int)"); + AssertBindsThroughTypeof(result, InternalExtensionClassName, "Twice", "typeof(int), typeof(int)"); } /// @@ -927,14 +927,14 @@ private static void AssertEntryAndNotSkipped(TransformWorkerClientResult result, Assert.That(FindEntry(result, methodName), Is.Not.Null, methodName + " must be an entry."); } - private static void AssertBindsByName( + private static void AssertBindsThroughTypeof( TransformWorkerClientResult result, string className, string methodName, string lookupTypes) { - string expected = "global::System.Type.GetType(\"" + TestNamespace + "." + className + ", " + TestAssemblyName - + "\", true), \"" + methodName + "\", new global::System.Type[]{" + lookupTypes + "})"; + string expected = "typeof(global::" + TestNamespace + "." + className + "), \"" + methodName + + "\", new global::System.Type[]{" + lookupTypes + "})"; Assert.That( WithoutWhitespace(result.Output.shimSource), Does.Contain(WithoutWhitespace(expected)), diff --git a/Assets/Tests/Editor/HotReload/TransformWorkerNonPublicClassExtensionCallTests.cs b/Assets/Tests/Editor/HotReload/TransformWorkerNonPublicClassExtensionCallTests.cs index d8211be3df..d538e19102 100644 --- a/Assets/Tests/Editor/HotReload/TransformWorkerNonPublicClassExtensionCallTests.cs +++ b/Assets/Tests/Editor/HotReload/TransformWorkerNonPublicClassExtensionCallTests.cs @@ -14,8 +14,8 @@ namespace io.github.hatayama.UnityCliLoop.Tests.Editor.HotReload { /// /// Transform worker coverage for lambdas and async bodies that call an extension method of a - /// non-public static class. Calls the accessor can carry become entries whose accessor binds - /// the class by name; the shapes it cannot carry are skipped with the reason of the check that + /// non-public static class. Calls the accessor can carry become entries whose accessor names + /// the class through typeof; the shapes it cannot carry are skipped with the reason of the check that /// refuses them, as they are for an internal extension method of a public class. /// public class TransformWorkerNonPublicClassExtensionCallTests @@ -23,7 +23,6 @@ public class TransformWorkerNonPublicClassExtensionCallTests private const string FixtureFileName = "HotReloadNonPublicClassExtensionCallFixtures.cs"; private const string FixtureProjectRelativePath = "Assets/Tests/Editor/HotReload/" + FixtureFileName; private const string Namespace = "io.github.hatayama.UnityCliLoop.Tests.Editor.HotReload"; - private const string TestAssemblyName = "UnityCLILoop.Tests.Editor.HotReload"; private const string AddedExtensionAnchor = " internal static int NonPublicPlusOne(this int value, int add)"; private const string StaticFormCallOfTriple = "HotReloadNonPublicClassExtensions.NonPublicTriple(_value, 6121)"; private const string OwnClassAddedMethodAnchor = @@ -48,17 +47,17 @@ public class TransformWorkerNonPublicClassExtensionCallTests /// What: a lambda or async body that calls an extension method of a non-public static class /// (reduced form, static form, chained, a public method of the class, or a class in a /// namespace named with a keyword) becomes an entry - /// whose shim calls the accessor with the receiver first, and whose accessor finds the class - /// by its name in the edited assembly. + /// whose shim calls the accessor with the receiver first, and whose accessor names the class + /// through typeof. /// [TestCase("6101", "ClosureCallsNonPublicClassExtension", @"__M_NonPublicTriple\w*\(__F__value\(__uloopInstance\), 6102\)", "HotReloadNonPublicClassExtensions")] [TestCase("6111", "AsyncCallsNonPublicClassExtension", @"__M_NonPublicTriple\w*\(__F__value\(__uloopInstance\), 6112\)", "HotReloadNonPublicClassExtensions")] [TestCase("6121", "ClosureCallsNonPublicClassExtensionInStaticForm", @"__M_NonPublicTriple\w*\(__F__value\(__uloopInstance\), 6122\)", "HotReloadNonPublicClassExtensions")] [TestCase("6131", "ClosureChainsNonPublicClassExtensions", @"__M_NonPublicPlusOne\w*\(__M_NonPublicTriple\w*\(__F__value\(__uloopInstance\), 6132\), 1\)", "HotReloadNonPublicClassExtensions")] [TestCase("6141", "ClosureCallsPublicExtensionOfNonPublicClass", @"__M_NonPublicDouble\w*\(__F__value\(__uloopInstance\), 6142\)", "HotReloadNonPublicClassExtensions")] - [TestCase("6311", "ClosureCallsKeywordNamespaceExtension", @"__M_KeywordNamespaceTriple\w*\(__F__value\(__uloopInstance\), 6312\)", "event.HotReloadKeywordNamespaceExtensions")] + [TestCase("6311", "ClosureCallsKeywordNamespaceExtension", @"__M_KeywordNamespaceTriple\w*\(__F__value\(__uloopInstance\), 6312\)", "@event.HotReloadKeywordNamespaceExtensions")] [TestCase("6291", "ClosureRecordsThroughPublicExtensionOfNonPublicClass", @"__M_NonPublicRecord\w*\(__F__value\(__uloopInstance\), ", "HotReloadNonPublicClassExtensions")] - public async Task NonPublicClassExtensionCall_IsAnEntryBindingTheClassByName( + public async Task NonPublicClassExtensionCall_IsAnEntryBindingTheClassThroughTypeof( string token, string methodName, string expectedCallPattern, @@ -71,7 +70,7 @@ public async Task NonPublicClassExtensionCall_IsAnEntryBindingTheClassByName( Assert.That(result.Output.shimSource, Does.Match(expectedCallPattern)); Assert.That( result.Output.shimSource, - Does.Contain("global::System.Type.GetType(\"" + Namespace + "." + className + ", " + TestAssemblyName + "\", true)")); + Does.Contain("typeof(global::" + Namespace + "." + className + ")")); } /// @@ -111,8 +110,8 @@ public async Task NonPublicClassExtensionCallWithoutAccessorShape_IsSkippedWithT /// /// What: a lambda that calls an extension method of a non-public static class this reload - /// adds is skipped for the class, because the class is not in the compiled assembly the - /// accessor would look it up in by name. + /// adds is skipped for the class, because the class is not in the compiled assembly the shim + /// compiles against, so the accessor's typeof of it would fail the shim compile. /// [Test] public async Task ExtensionCallOfNonPublicClassAddedInThisReload_IsSkippedForTheClass() diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/AccessorEntry.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/AccessorEntry.cs index c1bbdcddfb..0f6b9ef40c 100644 --- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/AccessorEntry.cs +++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/AccessorEntry.cs @@ -146,8 +146,8 @@ private bool BindsDeclaringClassByName(IAssemblySymbol targetAssembly) public IEnumerable EnumerateSignatureTypes() { - // Bind statements name ContainingType, including for static members; only an extension - // method of a non-public class names it as a string, which TryGetVisibilityFailure allows. + // Bind statements name ContainingType through typeof, including for static members; + // TryGetVisibilityFailure allows it only for an extension method of a non-public class. switch (Kind) { case AccessorKind.FieldRef: @@ -194,11 +194,18 @@ public FieldDeclarationSyntax EmitFieldDeclaration() } /// - /// What: the statement that binds this accessor. is the - /// compiled patch target read with every member visible, which an extension method of a - /// non-public class is looked up in; it may be null only when no entry needs that lookup. + /// What: the statement that binds this accessor. /// - public StatementSyntax EmitBindStatement(IAssemblySymbol targetAssembly) + /// + /// Why typeof also for an extension method of a non-public class: the shim compiles against + /// publicized references, and the Editor's Mono runtime does not check type access on the + /// ldtoken, so typeof of a top-level internal class binds (measured, every supported Editor is + /// Mono). On a runtime that did check it, the bind would throw in __BindAccessors, before any + /// patch is applied, not after the method was reported patched. ADR 0010 + /// (docs/adr/0010-hot-reload-internal-introduced-types.md) reopens Mono-only behavior when the + /// Editor moves to CoreCLR. + /// + public StatementSyntax EmitBindStatement() { string statement = Kind switch { @@ -206,7 +213,7 @@ public StatementSyntax EmitBindStatement(IAssemblySymbol targetAssembly) AccessorKind.MethodDelegate => BuildMethodDelegateBindStatement( MethodSymbol.Name, MethodSymbol, - BuildDeclaringTypeExpression(targetAssembly)), + "typeof(" + TypeDisplay(MethodSymbol.ContainingType) + ")"), AccessorKind.PropertyGetter => BuildMethodDelegateBindStatement( PropertySymbol.GetMethod.Name, PropertySymbol.GetMethod, @@ -226,20 +233,6 @@ public StatementSyntax EmitBindStatement(IAssemblySymbol targetAssembly) return SyntaxFactory.ParseStatement(statement); } - // Why by name for a non-public class: reflection reaches a non-public type whatever access - // checks the runtime applies to the shim's own IL. Under the Editor's Mono, typeof of a - // top-level internal class binds as well (measured), but the name lookup does not rely on that. - private string BuildDeclaringTypeExpression(IAssemblySymbol targetAssembly) - { - if (!BindsDeclaringClassByName(targetAssembly)) - { - return "typeof(" + TypeDisplay(MethodSymbol.ContainingType) + ")"; - } - - string assemblyQualifiedName = ExtensionClassNameBind.AssemblyQualifiedClassName(MethodSymbol, targetAssembly); - return "global::System.Type.GetType(\"" + EscapeStringLiteral(assemblyQualifiedName) + "\", true)"; - } - private string BuildDelegateTypeDisplayString() { switch (Kind) diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/ExtensionClassNameBind.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/ExtensionClassNameBind.cs index 746d51dc82..b10628ae86 100644 --- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/ExtensionClassNameBind.cs +++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/ExtensionClassNameBind.cs @@ -142,21 +142,6 @@ private static IMethodSymbol EditedOverloadOrNull( : null; } - /// - /// What: the assembly-qualified name the bind looks the class of up by, - /// in . - /// - internal static string AssemblyQualifiedClassName(IMethodSymbol method, IAssemblySymbol targetAssembly) - { - if (targetAssembly == null) - { - throw new InvalidOperationException( - "An accessor for an extension method of a non-public class needs the target assembly."); - } - - return ConstDriftCollector.ToReflectionMetadataName(method.ContainingType) + ", " + targetAssembly.Identity.Name; - } - // Why only a class of the patch target: a class of another assembly can share its metadata name // with an unrelated class of the target, and the accessor would bind that one. A class from the // edited source belongs to the target, as does one the worker reads from the target's metadata. diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/IndexerAccessorEmitter.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/IndexerAccessorEmitter.cs index 14367e789b..e08e8a3d7c 100644 --- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/IndexerAccessorEmitter.cs +++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/IndexerAccessorEmitter.cs @@ -146,8 +146,7 @@ private static void EmitAccessor( sourceProjectRelativePath, shimTypes, shimNames, - assemblyGlobalUsings, - typeState.TargetAssembly); + assemblyGlobalUsings); ShimTypeBuilder shimType = typeState.CurrentShimType; string shimMethodName = shimNames.NextShimMethodName(accessorSymbol.Name); MethodDeclarationSyntax rewrittenMethod = RewriteAccessorBody( diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/OrdinaryMethodShimTypes.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/OrdinaryMethodShimTypes.cs index 13563de1a7..db8530b7c4 100644 --- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/OrdinaryMethodShimTypes.cs +++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/OrdinaryMethodShimTypes.cs @@ -32,8 +32,7 @@ internal static ShimTypeBuilder EnsureShimType( shimTypeName, namespaceName, WorkerUsingCollector.CollectUsingsForType(root, typeState.TypeDeclaration, assemblyGlobalUsings), - typeState.SourceUnit.Input.ProjectRelativePath, - typeState.TargetAssembly); + typeState.SourceUnit.Input.ProjectRelativePath); shimTypes.Add(typeState.CurrentShimType); return typeState.CurrentShimType; } diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/PropertyGetterEmitter.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/PropertyGetterEmitter.cs index 14786d0d7a..49232e7cea 100644 --- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/PropertyGetterEmitter.cs +++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/PropertyGetterEmitter.cs @@ -284,8 +284,7 @@ internal static ShimTypeBuilder AppendPropertyGetterEntry( addedMethodCatalog, addedFieldCatalog, addedPropertyCatalog, - homeAssemblyName, - targetAssembly); + homeAssemblyName); } internal static ShimTypeBuilder EmitPropertyGetterShim( @@ -310,8 +309,7 @@ internal static ShimTypeBuilder EmitPropertyGetterShim( AddedMethodCatalog addedMethodCatalog, AddedFieldCatalog addedFieldCatalog, AddedPropertyCatalog addedPropertyCatalog, - string homeAssemblyName, - IAssemblySymbol targetAssembly) + string homeAssemblyName) { currentShimType = EnsureShimType( currentShimType, @@ -321,8 +319,7 @@ internal static ShimTypeBuilder EmitPropertyGetterShim( sourceProjectRelativePath, shimTypes, shimNames, - assemblyGlobalUsings, - targetAssembly); + assemblyGlobalUsings); string shimMethodName = shimNames.NextShimMethodName(ShimBaseName(explicitImplementations, getterSymbol)); @@ -407,8 +404,7 @@ internal static ShimTypeBuilder EnsureShimType( string sourceProjectRelativePath, List shimTypes, ShimNameAllocator shimNames, - List assemblyGlobalUsings, - IAssemblySymbol targetAssembly) + List assemblyGlobalUsings) { if (currentShimType != null) { @@ -424,8 +420,7 @@ internal static ShimTypeBuilder EnsureShimType( shimTypeName, namespaceName, WorkerUsingCollector.CollectUsingsForType(root, typeDeclaration, assemblyGlobalUsings), - sourceProjectRelativePath, - targetAssembly); + sourceProjectRelativePath); shimTypes.Add(shimType); return shimType; } diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/PropertySetterEmitter.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/PropertySetterEmitter.cs index 3f41545814..2d939a6bfe 100644 --- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/PropertySetterEmitter.cs +++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/PropertySetterEmitter.cs @@ -136,8 +136,7 @@ private static void EmitPropertySetter( sourceProjectRelativePath, shimTypes, shimNames, - assemblyGlobalUsings, - typeState.TargetAssembly); + assemblyGlobalUsings); ShimTypeBuilder shimType = typeState.CurrentShimType; string shimMethodName = shimNames.NextShimMethodName(PropertyGetterEmitter.ShimBaseName(typeState.SourceUnit.ExplicitImplementations, setterSymbol)); MethodDeclarationSyntax rewrittenMethod = RewritePropertySetterBody( diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/ShimTypeBuilder.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/ShimTypeBuilder.cs index 9cf12d7180..18fb827746 100644 --- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/ShimTypeBuilder.cs +++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/ShimTypeBuilder.cs @@ -26,11 +26,9 @@ public ShimTypeBuilder( string shimTypeName, string namespaceName, List usings, - string sourceProjectRelativePath, - IAssemblySymbol targetAssembly) + string sourceProjectRelativePath) { ShimTypeName = shimTypeName; - TargetAssembly = targetAssembly; NamespaceName = namespaceName ?? string.Empty; Usings = usings ?? new List(); SourceProjectRelativePath = sourceProjectRelativePath; @@ -45,10 +43,6 @@ public ShimTypeBuilder( public string NamespaceName { get; } - // The compiled patch target read with every member visible, or null when the run could not read - // it. The bind of an extension method of a non-public class looks its class up in it by name. - public IAssemblySymbol TargetAssembly { get; } - public List Usings { get; } /// @@ -112,7 +106,7 @@ private MethodDeclarationSyntax EmitBindAccessorsMethod() List statements = new List(); foreach (AccessorEntry accessor in AccessorPlan.Entries) { - statements.Add(accessor.EmitBindStatement(TargetAssembly)); + statements.Add(accessor.EmitBindStatement()); } return SyntaxFactory.MethodDeclaration( From a266cd9ada1489fd3b28c3b64fed4b3f8bca6617 Mon Sep 17 00:00:00 2001 From: hatayama Date: Sat, 28 Nov 2026 20:24:06 +0900 Subject: [PATCH 2/4] refactor: rename the extension-class bind rules now that nothing is found by name With the accessor naming the class through typeof, the identifiers that described a lookup by name misdescribe the code: - ExtensionClassNameBind -> NonPublicExtensionClassBind (file renamed too) - FindsClassByName -> AllowsNonPublicClass - AccessorEntry.BindsDeclaringClassByName -> AllowsNonPublicDeclaringClass Their comments, and the twin-overload comment in AccessibilityRules, now say what they decide: whether the accessor may name a non-public class, why the class must already be compiled (typeof of a class this reload adds would fail the shim compile), and why the bound overload must be the edited one. No behavior change. --- .../TransformWorker~/AccessibilityRules.cs | 2 +- .../AccessorAccessRegistrar.cs | 2 +- .../TransformWorker~/AccessorEntry.cs | 10 ++--- ...Bind.cs => NonPublicExtensionClassBind.cs} | 40 +++++++++---------- 4 files changed, 26 insertions(+), 28 deletions(-) rename Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/{ExtensionClassNameBind.cs => NonPublicExtensionClassBind.cs} (77%) diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/AccessibilityRules.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/AccessibilityRules.cs index 310ed27d5a..f569c16a60 100644 --- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/AccessibilityRules.cs +++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/AccessibilityRules.cs @@ -87,7 +87,7 @@ internal static ISymbol BoundSymbolOrNull(SemanticModel semanticModel, SyntaxNod // What: the candidate of the twin's compiled class that has the signature of the overload the // edited source calls, or null when the enforcing binding resolves no method or no candidate // matches. Why not any candidate of that class: the twin is picked to refuse the call, and any - // overload refuses it, but an accessor that reaches the class by name binds the overload it is + // overload refuses it, but an accessor of a non-public class binds the overload it is // given, which must be the one the source calls (Pick(int) over Pick(long) for an int argument). private static IMethodSymbol FindTwinOfTheEditedOverloadOrNull( SemanticModel semanticModel, diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/AccessorAccessRegistrar.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/AccessorAccessRegistrar.cs index d251f5cc20..8b8fd06003 100644 --- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/AccessorAccessRegistrar.cs +++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/AccessorAccessRegistrar.cs @@ -502,7 +502,7 @@ internal static bool TryRegisterInvocation( return false; } - rejectReason = ExtensionClassNameBind.FindRejectReasonOrNull(semanticModel, invocation, methodSymbol); + rejectReason = NonPublicExtensionClassBind.FindRejectReasonOrNull(semanticModel, invocation, methodSymbol); if (rejectReason != null) { return false; diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/AccessorEntry.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/AccessorEntry.cs index 0f6b9ef40c..afdb1bd65e 100644 --- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/AccessorEntry.cs +++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/AccessorEntry.cs @@ -117,11 +117,11 @@ public static AccessorEntry ForEventBackingField( /// public bool TryGetVisibilityFailure(IAssemblySymbol targetAssembly, out WorkerReason reason) { - bool bindsClassByName = BindsDeclaringClassByName(targetAssembly) - && ExtensionClassNameBind.IsCompiledIn(MethodSymbol, targetAssembly); + bool allowsNonPublicClass = AllowsNonPublicDeclaringClass(targetAssembly) + && NonPublicExtensionClassBind.IsCompiledIn(MethodSymbol, targetAssembly); foreach (ITypeSymbol typeSymbol in EnumerateSignatureTypes()) { - if (bindsClassByName && SymbolEqualityComparer.Default.Equals(typeSymbol, MethodSymbol.ContainingType)) + if (allowsNonPublicClass && SymbolEqualityComparer.Default.Equals(typeSymbol, MethodSymbol.ContainingType)) { continue; } @@ -139,9 +139,9 @@ public bool TryGetVisibilityFailure(IAssemblySymbol targetAssembly, out WorkerRe return false; } - private bool BindsDeclaringClassByName(IAssemblySymbol targetAssembly) + private bool AllowsNonPublicDeclaringClass(IAssemblySymbol targetAssembly) { - return Kind == AccessorKind.MethodDelegate && ExtensionClassNameBind.FindsClassByName(MethodSymbol, targetAssembly); + return Kind == AccessorKind.MethodDelegate && NonPublicExtensionClassBind.AllowsNonPublicClass(MethodSymbol, targetAssembly); } public IEnumerable EnumerateSignatureTypes() diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/ExtensionClassNameBind.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/NonPublicExtensionClassBind.cs similarity index 77% rename from Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/ExtensionClassNameBind.cs rename to Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/NonPublicExtensionClassBind.cs index b10628ae86..3344759dd7 100644 --- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/ExtensionClassNameBind.cs +++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/NonPublicExtensionClassBind.cs @@ -17,27 +17,25 @@ using io.github.hatayama.UnityCliLoop.FirstPartyTools; /// -/// What: when an accessor finds the class of an extension method by its name, because the class is -/// not public, and what that name is. The class must be compiled into the patch target, and the call -/// must bind to the overload the edited source calls. +/// What: when an accessor may bind an extension method whose class is not public. The class must be +/// compiled into the patch target, and the call must bind to the overload the edited source calls. /// -internal static class ExtensionClassNameBind +internal static class NonPublicExtensionClassBind { /// - /// What: whether the accessor for , an unreduced method, finds its class - /// by name: the method is an extension method whose class is not public in the edited source or - /// in (read with every member visible, or null when the run - /// could not read it). + /// What: whether the accessor for , an unreduced method, may name a + /// non-public class: the method is an extension method whose class is not public in the edited + /// source or in (read with every member visible, or null when + /// the run could not read it). /// /// /// Why only an extension method: the language makes its class top-level, non-generic and static, - /// so the metadata name alone finds the class, and the delegate type never names it, because the - /// class is not a parameter. Another non-public class may be generic or nested in one, which a - /// name lookup cannot construct, so a method of such a class stays refused. Why the compiled class - /// too: one edit can make the class public while the class that runs stays internal, and the bind - /// finds the class by name whenever the class that runs is not public. + /// and the delegate type never names it, because the class is not a parameter; only the bind's + /// typeof does. A method of another non-public class stays refused. Why the compiled class too: + /// one edit can make the class public while the class that runs stays internal, and the accessor + /// binds the class that runs. /// - internal static bool FindsClassByName(IMethodSymbol method, IAssemblySymbol targetAssembly) + internal static bool AllowsNonPublicClass(IMethodSymbol method, IAssemblySymbol targetAssembly) { if (!method.IsExtensionMethod) { @@ -58,9 +56,9 @@ internal static bool FindsClassByName(IMethodSymbol method, IAssemblySymbol targ /// and holds the method with the same return type or not at all. /// /// - /// Why the class must already be compiled: the bind looks it up by name in that assembly when the - /// shim loads, and a class this reload adds is not there, so the bind would throw and fail the - /// whole file instead of skipping the one method. Why a method this reload adds passes: only its + /// Why the class must already be compiled: the shim compiles against a copy of that assembly, and + /// a class this reload adds is not there, so the bind's typeof of it would fail the whole file + /// instead of skipping the one method. Why a method this reload adds passes: only its /// static-form call gets this far, the reduced form being refused before, and the added-method /// rewrite replaces that call, so the shim binds no accessor for it. Why a changed return type /// fails: the bind would find the compiled method by its parameters and could not make a delegate @@ -77,13 +75,13 @@ internal static bool IsCompiledIn(IMethodSymbol method, IAssemblySymbol targetAs /// /// What: the reason an accessor may not bind , the unreduced /// method the worker bound to, or null when it may. Only a method of - /// a class that is not public is checked; the reason is the one the class would get without the - /// lookup by name, or the [Conditional] one. + /// a class that is not public is checked; the reason is the one the class would get if the + /// accessor could not name it, or the [Conditional] one. /// /// /// Why at the call: when the bound method's class is not public, the worker's binding may have - /// stood a compiled twin in for the call, and an accessor that finds the class by name binds the - /// method it is given, so it must be the one the edited source calls. Why read [Conditional] from + /// stood a compiled twin in for the call, and an accessor of a non-public class binds the method + /// it is given, so it must be the one the edited source calls. Why read [Conditional] from /// the edited overload: a twin carries the attributes of the last compile, and an edit that makes /// the method conditional means the compiler omits the call. /// From d1404f40dfdc4c4c5db3032954b198b187b4d7fb Mon Sep 17 00:00:00 2001 From: hatayama Date: Sat, 28 Nov 2026 20:39:41 +0900 Subject: [PATCH 3/4] docs: describe the typeof bind of a non-public extension class accurately Review follow-ups for the typeof bind: - IsCompiledIn: the reason a class this reload adds is refused is now the measured one. With the check forced to pass, the reload reported the lambda Patched and its first call threw MethodAccessException from the shim; it neither failed the shim compile nor threw at bind. The worker test's description says the same. - EmitBindStatement remarks record the one fail-closed case that changed: a referenced assembly with a public type of the class's full name makes the shim's typeof ambiguous (CS0433), so the file's entries are dropped and recompiled, or the file fails. A public class had the same limit. - Fixture and E2E comments no longer say the accessor finds the class by name; the keyword-namespace fixture now guards that typeof escapes the namespace as @event. - scope-and-limits.md: an extension method of an internal static class applies because the accessor names the class through typeof. Copies in .claude/ and .agents/ regenerated. --- .../uloop-hot-reload/references/scope-and-limits.md | 2 +- .../uloop-hot-reload/references/scope-and-limits.md | 2 +- .../HotReloadNonPublicClassExtensionCallE2ETests.cs | 4 ++-- .../HotReloadNonPublicClassExtensionCallFixtures.cs | 8 ++++---- .../TransformWorkerNonPublicClassExtensionCallTests.cs | 5 +++-- .../HotReload/Skill/references/scope-and-limits.md | 2 +- .../HotReload/TransformWorker~/AccessorEntry.cs | 6 +++++- .../TransformWorker~/NonPublicExtensionClassBind.cs | 6 +++--- 8 files changed, 20 insertions(+), 15 deletions(-) diff --git a/.agents/skills/uloop-hot-reload/references/scope-and-limits.md b/.agents/skills/uloop-hot-reload/references/scope-and-limits.md index 71ad0e688d..6dc99723a8 100644 --- a/.agents/skills/uloop-hot-reload/references/scope-and-limits.md +++ b/.agents/skills/uloop-hot-reload/references/scope-and-limits.md @@ -469,7 +469,7 @@ source on disk. When a run skips a method it had patched before, `Warnings` name | Base call to a method marked `[Conditional]` | The compiler removes the call, and the evaluation of its arguments, when the symbol is not defined; hot reload cannot do the same. Run `uloop compile` | | Base call to a method whose base type declares another overload with the same parameter types once its type arguments are filled in (for example `Pick(T)` and `Pick(int)` on `Base`) | Hot reload finds the base method by name and parameter types, which cannot tell these overloads apart. Run `uloop compile` | | Base call to a method the compiled assembly does not hold yet (added or re-signatured since the last compile) | Run `uloop compile` | -| Private/internal access inside an async/iterator/closure body has no accessor-delegate shape | Conditional access (`?.`), indexers, initializer member assignments, a member named in a property pattern (`x is { _count: 0 }`, or a link of `{ A.B: 0 }`; read the same member path outside the pattern instead: `x._count == 0`, `x.A.B == 0`), and calls with `ref`/`out`/`in`, named, omitted optional, or expanded `params` arguments (or to generic, by-ref-returning, or `[Conditional]` methods, or methods with a ref struct parameter or return type) cannot be rewritten to accessor delegates. An extension method of an `internal` static class applies in either form, because the accessor finds the class by name, as long as the last compile built that class into the edited assembly and the class is declared in a file this reload passes or pulls back in: one in a class this reload adds or in a file the reload does not see is refused, as is one whose return type the same edit changes, a method of an `internal` class that is not an extension method, or one whose parameter or return types are not public. Neither can ref-returning properties, nor these writes to a property through a private/internal setter: `??=`, a compound write whose receiver could be evaluated twice, an assignment whose value is used (a lambda or `=>` member that returns nothing and is only the assignment applies), and a deconstruction. A compound write (`+=`, `??=`, and the like) to a property whose getter is private/internal and whose setter is not is refused as well. The same writes to a private/internal field declared on a class apply, static fields included. In an async body, such a field is also refused when the expression uses it by reference and awaits after that use: passed as `ref`, `out` or `in`, the receiver of a call that takes it by reference, assigned to (`=`, `+=`, a deconstruction), or a struct field whose member or indexer is assigned, as in `M(ref _count, await GetAsync())` or `_count += await GetAsync()`. This holds whatever the call is, a method added in the same reload included; await into a local first, as in `int value = await GetAsync();`, and use the local. That moves the field's read after the await; when the original order matters, read the field into a local before the await as well: `int count = _count; int value = await GetAsync(); _count = count + value;`. A private/internal instance member declared on a struct is refused. An inaccessible method the compiler calls for `await`, `foreach`, `await foreach`, a deconstruction or positional pattern, a collection initializer, a query expression, an interpolated string handler, an index or range (`^1`, `a..b`), a ref struct's `using`, or `await using` is refused as well, including the awaiter of the value `DisposeAsync` or `MoveNextAsync` returns. These limits apply to compiled members; a method added in the same reload is reached directly, whatever its arguments, except a generic, by-ref-returning, or `[Conditional]` added method, which is refused as a compiled one is. An added extension method called on a receiver, `receiver.Method(...)`, gets the outcome of its static form, `Extensions.Method(receiver, ...)` (`Extensions.Method(ref receiver, ...)` for a `this ref` method), except through conditional access (`receiver?.Method(...)`), which is skipped as every added-method call through `?.` is; write the null check and the static form instead. A compiled private/internal static property can be read, assigned, and compound-assigned | +| Private/internal access inside an async/iterator/closure body has no accessor-delegate shape | Conditional access (`?.`), indexers, initializer member assignments, a member named in a property pattern (`x is { _count: 0 }`, or a link of `{ A.B: 0 }`; read the same member path outside the pattern instead: `x._count == 0`, `x.A.B == 0`), and calls with `ref`/`out`/`in`, named, omitted optional, or expanded `params` arguments (or to generic, by-ref-returning, or `[Conditional]` methods, or methods with a ref struct parameter or return type) cannot be rewritten to accessor delegates. An extension method of an `internal` static class applies in either form, because the accessor names the class through typeof, as long as the last compile built that class into the edited assembly and the class is declared in a file this reload passes or pulls back in: one in a class this reload adds or in a file the reload does not see is refused, as is one whose return type the same edit changes, a method of an `internal` class that is not an extension method, or one whose parameter or return types are not public. Neither can ref-returning properties, nor these writes to a property through a private/internal setter: `??=`, a compound write whose receiver could be evaluated twice, an assignment whose value is used (a lambda or `=>` member that returns nothing and is only the assignment applies), and a deconstruction. A compound write (`+=`, `??=`, and the like) to a property whose getter is private/internal and whose setter is not is refused as well. The same writes to a private/internal field declared on a class apply, static fields included. In an async body, such a field is also refused when the expression uses it by reference and awaits after that use: passed as `ref`, `out` or `in`, the receiver of a call that takes it by reference, assigned to (`=`, `+=`, a deconstruction), or a struct field whose member or indexer is assigned, as in `M(ref _count, await GetAsync())` or `_count += await GetAsync()`. This holds whatever the call is, a method added in the same reload included; await into a local first, as in `int value = await GetAsync();`, and use the local. That moves the field's read after the await; when the original order matters, read the field into a local before the await as well: `int count = _count; int value = await GetAsync(); _count = count + value;`. A private/internal instance member declared on a struct is refused. An inaccessible method the compiler calls for `await`, `foreach`, `await foreach`, a deconstruction or positional pattern, a collection initializer, a query expression, an interpolated string handler, an index or range (`^1`, `a..b`), a ref struct's `using`, or `await using` is refused as well, including the awaiter of the value `DisposeAsync` or `MoveNextAsync` returns. These limits apply to compiled members; a method added in the same reload is reached directly, whatever its arguments, except a generic, by-ref-returning, or `[Conditional]` added method, which is refused as a compiled one is. An added extension method called on a receiver, `receiver.Method(...)`, gets the outcome of its static form, `Extensions.Method(receiver, ...)` (`Extensions.Method(ref receiver, ...)` for a `this ref` method), except through conditional access (`receiver?.Method(...)`), which is skipped as every added-method call through `?.` is; write the null check and the static form instead. A compiled private/internal static property can be read, assigned, and compound-assigned | | An async/iterator/closure body of a type not visible outside its assembly reaches a compiled member | An accessor delegate has to name its host, which a shim cannot do for an `internal` class or a class nested in one, so this refuses even a `public` member of that class. A body reaching only methods added in the same reload applies. In a lambda or local function, copy the compiled member into a local outside it; otherwise run `uloop compile` | | An async/iterator/closure body references a private/internal type | Accessor delegates rescue member access, not type references; the body still cannot JIT-compile from the shim assembly. The one exception is the class of a call written in the static form, `Extensions.Method(receiver, ...)`, inside the lambda, local function or async body, when the call itself is rewritten, because the rewritten call no longer names the class | | A declared return or parameter type cannot be resolved (a new type this reload could not introduce, a missing using, or a typo) | Skipped; a supported new type declared in an edited file of the same assembly is introduced by this reload, so check `Warnings` for the refusal reason (`introduced-types.md`); otherwise add the type or the `using`, or fix the typo, then run `uloop compile` | diff --git a/.claude/skills/uloop-hot-reload/references/scope-and-limits.md b/.claude/skills/uloop-hot-reload/references/scope-and-limits.md index 71ad0e688d..6dc99723a8 100644 --- a/.claude/skills/uloop-hot-reload/references/scope-and-limits.md +++ b/.claude/skills/uloop-hot-reload/references/scope-and-limits.md @@ -469,7 +469,7 @@ source on disk. When a run skips a method it had patched before, `Warnings` name | Base call to a method marked `[Conditional]` | The compiler removes the call, and the evaluation of its arguments, when the symbol is not defined; hot reload cannot do the same. Run `uloop compile` | | Base call to a method whose base type declares another overload with the same parameter types once its type arguments are filled in (for example `Pick(T)` and `Pick(int)` on `Base`) | Hot reload finds the base method by name and parameter types, which cannot tell these overloads apart. Run `uloop compile` | | Base call to a method the compiled assembly does not hold yet (added or re-signatured since the last compile) | Run `uloop compile` | -| Private/internal access inside an async/iterator/closure body has no accessor-delegate shape | Conditional access (`?.`), indexers, initializer member assignments, a member named in a property pattern (`x is { _count: 0 }`, or a link of `{ A.B: 0 }`; read the same member path outside the pattern instead: `x._count == 0`, `x.A.B == 0`), and calls with `ref`/`out`/`in`, named, omitted optional, or expanded `params` arguments (or to generic, by-ref-returning, or `[Conditional]` methods, or methods with a ref struct parameter or return type) cannot be rewritten to accessor delegates. An extension method of an `internal` static class applies in either form, because the accessor finds the class by name, as long as the last compile built that class into the edited assembly and the class is declared in a file this reload passes or pulls back in: one in a class this reload adds or in a file the reload does not see is refused, as is one whose return type the same edit changes, a method of an `internal` class that is not an extension method, or one whose parameter or return types are not public. Neither can ref-returning properties, nor these writes to a property through a private/internal setter: `??=`, a compound write whose receiver could be evaluated twice, an assignment whose value is used (a lambda or `=>` member that returns nothing and is only the assignment applies), and a deconstruction. A compound write (`+=`, `??=`, and the like) to a property whose getter is private/internal and whose setter is not is refused as well. The same writes to a private/internal field declared on a class apply, static fields included. In an async body, such a field is also refused when the expression uses it by reference and awaits after that use: passed as `ref`, `out` or `in`, the receiver of a call that takes it by reference, assigned to (`=`, `+=`, a deconstruction), or a struct field whose member or indexer is assigned, as in `M(ref _count, await GetAsync())` or `_count += await GetAsync()`. This holds whatever the call is, a method added in the same reload included; await into a local first, as in `int value = await GetAsync();`, and use the local. That moves the field's read after the await; when the original order matters, read the field into a local before the await as well: `int count = _count; int value = await GetAsync(); _count = count + value;`. A private/internal instance member declared on a struct is refused. An inaccessible method the compiler calls for `await`, `foreach`, `await foreach`, a deconstruction or positional pattern, a collection initializer, a query expression, an interpolated string handler, an index or range (`^1`, `a..b`), a ref struct's `using`, or `await using` is refused as well, including the awaiter of the value `DisposeAsync` or `MoveNextAsync` returns. These limits apply to compiled members; a method added in the same reload is reached directly, whatever its arguments, except a generic, by-ref-returning, or `[Conditional]` added method, which is refused as a compiled one is. An added extension method called on a receiver, `receiver.Method(...)`, gets the outcome of its static form, `Extensions.Method(receiver, ...)` (`Extensions.Method(ref receiver, ...)` for a `this ref` method), except through conditional access (`receiver?.Method(...)`), which is skipped as every added-method call through `?.` is; write the null check and the static form instead. A compiled private/internal static property can be read, assigned, and compound-assigned | +| Private/internal access inside an async/iterator/closure body has no accessor-delegate shape | Conditional access (`?.`), indexers, initializer member assignments, a member named in a property pattern (`x is { _count: 0 }`, or a link of `{ A.B: 0 }`; read the same member path outside the pattern instead: `x._count == 0`, `x.A.B == 0`), and calls with `ref`/`out`/`in`, named, omitted optional, or expanded `params` arguments (or to generic, by-ref-returning, or `[Conditional]` methods, or methods with a ref struct parameter or return type) cannot be rewritten to accessor delegates. An extension method of an `internal` static class applies in either form, because the accessor names the class through typeof, as long as the last compile built that class into the edited assembly and the class is declared in a file this reload passes or pulls back in: one in a class this reload adds or in a file the reload does not see is refused, as is one whose return type the same edit changes, a method of an `internal` class that is not an extension method, or one whose parameter or return types are not public. Neither can ref-returning properties, nor these writes to a property through a private/internal setter: `??=`, a compound write whose receiver could be evaluated twice, an assignment whose value is used (a lambda or `=>` member that returns nothing and is only the assignment applies), and a deconstruction. A compound write (`+=`, `??=`, and the like) to a property whose getter is private/internal and whose setter is not is refused as well. The same writes to a private/internal field declared on a class apply, static fields included. In an async body, such a field is also refused when the expression uses it by reference and awaits after that use: passed as `ref`, `out` or `in`, the receiver of a call that takes it by reference, assigned to (`=`, `+=`, a deconstruction), or a struct field whose member or indexer is assigned, as in `M(ref _count, await GetAsync())` or `_count += await GetAsync()`. This holds whatever the call is, a method added in the same reload included; await into a local first, as in `int value = await GetAsync();`, and use the local. That moves the field's read after the await; when the original order matters, read the field into a local before the await as well: `int count = _count; int value = await GetAsync(); _count = count + value;`. A private/internal instance member declared on a struct is refused. An inaccessible method the compiler calls for `await`, `foreach`, `await foreach`, a deconstruction or positional pattern, a collection initializer, a query expression, an interpolated string handler, an index or range (`^1`, `a..b`), a ref struct's `using`, or `await using` is refused as well, including the awaiter of the value `DisposeAsync` or `MoveNextAsync` returns. These limits apply to compiled members; a method added in the same reload is reached directly, whatever its arguments, except a generic, by-ref-returning, or `[Conditional]` added method, which is refused as a compiled one is. An added extension method called on a receiver, `receiver.Method(...)`, gets the outcome of its static form, `Extensions.Method(receiver, ...)` (`Extensions.Method(ref receiver, ...)` for a `this ref` method), except through conditional access (`receiver?.Method(...)`), which is skipped as every added-method call through `?.` is; write the null check and the static form instead. A compiled private/internal static property can be read, assigned, and compound-assigned | | An async/iterator/closure body of a type not visible outside its assembly reaches a compiled member | An accessor delegate has to name its host, which a shim cannot do for an `internal` class or a class nested in one, so this refuses even a `public` member of that class. A body reaching only methods added in the same reload applies. In a lambda or local function, copy the compiled member into a local outside it; otherwise run `uloop compile` | | An async/iterator/closure body references a private/internal type | Accessor delegates rescue member access, not type references; the body still cannot JIT-compile from the shim assembly. The one exception is the class of a call written in the static form, `Extensions.Method(receiver, ...)`, inside the lambda, local function or async body, when the call itself is rewritten, because the rewritten call no longer names the class | | A declared return or parameter type cannot be resolved (a new type this reload could not introduce, a missing using, or a typo) | Skipped; a supported new type declared in an edited file of the same assembly is introduced by this reload, so check `Warnings` for the refusal reason (`introduced-types.md`); otherwise add the type or the `using`, or fix the typo, then run `uloop compile` | diff --git a/Assets/Tests/Editor/HotReload/HotReloadNonPublicClassExtensionCallE2ETests.cs b/Assets/Tests/Editor/HotReload/HotReloadNonPublicClassExtensionCallE2ETests.cs index df43a0df85..c2ed3ed25d 100644 --- a/Assets/Tests/Editor/HotReload/HotReloadNonPublicClassExtensionCallE2ETests.cs +++ b/Assets/Tests/Editor/HotReload/HotReloadNonPublicClassExtensionCallE2ETests.cs @@ -200,8 +200,8 @@ public async Task Run_ClosureInNonPublicClassCallingItsAddedMethodInStaticForm_I /// /// What: a lambda that calls an extension method of an internal static class in a namespace - /// named with a keyword is Patched and returns the edited value, because the accessor looks - /// the class up by its metadata name. + /// named with a keyword is Patched and returns the edited value, because the accessor's + /// typeof escapes the keyword (@event). /// [Test] public async Task Run_ClosureCallingExtensionInKeywordNamedNamespace_IsPatched() diff --git a/Assets/Tests/Editor/HotReload/HotReloadNonPublicClassExtensionCallFixtures.cs b/Assets/Tests/Editor/HotReload/HotReloadNonPublicClassExtensionCallFixtures.cs index 5f9b50b6bc..8e9d3c8de4 100644 --- a/Assets/Tests/Editor/HotReload/HotReloadNonPublicClassExtensionCallFixtures.cs +++ b/Assets/Tests/Editor/HotReload/HotReloadNonPublicClassExtensionCallFixtures.cs @@ -26,8 +26,8 @@ public sealed class HotReloadNonPublicMarked : IHotReloadNonPublicMarker /// /// Internal static class whose extension methods the host below calls, declared in the same - /// file as the host. A lambda or async body that calls one needs an accessor, which finds the - /// class by name because the class is not public. + /// file as the host. A lambda or async body that calls one needs an accessor, which names the + /// class through typeof although the class is not public. /// internal static class HotReloadNonPublicClassExtensions { @@ -285,8 +285,8 @@ private int RecordTraceArgument(int add) namespace io.github.hatayama.UnityCliLoop.Tests.Editor.HotReload.@event { /// - /// Internal static class in a namespace named with a keyword, so the lookup of the class by name - /// must use its metadata name (event), not the escaped display (@event). + /// Internal static class in a namespace named with a keyword, so the accessor's typeof of the + /// class must escape that namespace as @event. /// internal static class HotReloadKeywordNamespaceExtensions { diff --git a/Assets/Tests/Editor/HotReload/TransformWorkerNonPublicClassExtensionCallTests.cs b/Assets/Tests/Editor/HotReload/TransformWorkerNonPublicClassExtensionCallTests.cs index d538e19102..0dc09e2f5e 100644 --- a/Assets/Tests/Editor/HotReload/TransformWorkerNonPublicClassExtensionCallTests.cs +++ b/Assets/Tests/Editor/HotReload/TransformWorkerNonPublicClassExtensionCallTests.cs @@ -110,8 +110,9 @@ public async Task NonPublicClassExtensionCallWithoutAccessorShape_IsSkippedWithT /// /// What: a lambda that calls an extension method of a non-public static class this reload - /// adds is skipped for the class, because the class is not in the compiled assembly the shim - /// compiles against, so the accessor's typeof of it would fail the shim compile. + /// adds is skipped for the class, because the class is not in the compiled assembly: without + /// that check the reload would report the method Patched and its first call would throw + /// MethodAccessException. /// [Test] public async Task ExtensionCallOfNonPublicClassAddedInThisReload_IsSkippedForTheClass() diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/Skill/references/scope-and-limits.md b/Packages/src/Editor/FirstPartyTools/HotReload/Skill/references/scope-and-limits.md index 71ad0e688d..6dc99723a8 100644 --- a/Packages/src/Editor/FirstPartyTools/HotReload/Skill/references/scope-and-limits.md +++ b/Packages/src/Editor/FirstPartyTools/HotReload/Skill/references/scope-and-limits.md @@ -469,7 +469,7 @@ source on disk. When a run skips a method it had patched before, `Warnings` name | Base call to a method marked `[Conditional]` | The compiler removes the call, and the evaluation of its arguments, when the symbol is not defined; hot reload cannot do the same. Run `uloop compile` | | Base call to a method whose base type declares another overload with the same parameter types once its type arguments are filled in (for example `Pick(T)` and `Pick(int)` on `Base`) | Hot reload finds the base method by name and parameter types, which cannot tell these overloads apart. Run `uloop compile` | | Base call to a method the compiled assembly does not hold yet (added or re-signatured since the last compile) | Run `uloop compile` | -| Private/internal access inside an async/iterator/closure body has no accessor-delegate shape | Conditional access (`?.`), indexers, initializer member assignments, a member named in a property pattern (`x is { _count: 0 }`, or a link of `{ A.B: 0 }`; read the same member path outside the pattern instead: `x._count == 0`, `x.A.B == 0`), and calls with `ref`/`out`/`in`, named, omitted optional, or expanded `params` arguments (or to generic, by-ref-returning, or `[Conditional]` methods, or methods with a ref struct parameter or return type) cannot be rewritten to accessor delegates. An extension method of an `internal` static class applies in either form, because the accessor finds the class by name, as long as the last compile built that class into the edited assembly and the class is declared in a file this reload passes or pulls back in: one in a class this reload adds or in a file the reload does not see is refused, as is one whose return type the same edit changes, a method of an `internal` class that is not an extension method, or one whose parameter or return types are not public. Neither can ref-returning properties, nor these writes to a property through a private/internal setter: `??=`, a compound write whose receiver could be evaluated twice, an assignment whose value is used (a lambda or `=>` member that returns nothing and is only the assignment applies), and a deconstruction. A compound write (`+=`, `??=`, and the like) to a property whose getter is private/internal and whose setter is not is refused as well. The same writes to a private/internal field declared on a class apply, static fields included. In an async body, such a field is also refused when the expression uses it by reference and awaits after that use: passed as `ref`, `out` or `in`, the receiver of a call that takes it by reference, assigned to (`=`, `+=`, a deconstruction), or a struct field whose member or indexer is assigned, as in `M(ref _count, await GetAsync())` or `_count += await GetAsync()`. This holds whatever the call is, a method added in the same reload included; await into a local first, as in `int value = await GetAsync();`, and use the local. That moves the field's read after the await; when the original order matters, read the field into a local before the await as well: `int count = _count; int value = await GetAsync(); _count = count + value;`. A private/internal instance member declared on a struct is refused. An inaccessible method the compiler calls for `await`, `foreach`, `await foreach`, a deconstruction or positional pattern, a collection initializer, a query expression, an interpolated string handler, an index or range (`^1`, `a..b`), a ref struct's `using`, or `await using` is refused as well, including the awaiter of the value `DisposeAsync` or `MoveNextAsync` returns. These limits apply to compiled members; a method added in the same reload is reached directly, whatever its arguments, except a generic, by-ref-returning, or `[Conditional]` added method, which is refused as a compiled one is. An added extension method called on a receiver, `receiver.Method(...)`, gets the outcome of its static form, `Extensions.Method(receiver, ...)` (`Extensions.Method(ref receiver, ...)` for a `this ref` method), except through conditional access (`receiver?.Method(...)`), which is skipped as every added-method call through `?.` is; write the null check and the static form instead. A compiled private/internal static property can be read, assigned, and compound-assigned | +| Private/internal access inside an async/iterator/closure body has no accessor-delegate shape | Conditional access (`?.`), indexers, initializer member assignments, a member named in a property pattern (`x is { _count: 0 }`, or a link of `{ A.B: 0 }`; read the same member path outside the pattern instead: `x._count == 0`, `x.A.B == 0`), and calls with `ref`/`out`/`in`, named, omitted optional, or expanded `params` arguments (or to generic, by-ref-returning, or `[Conditional]` methods, or methods with a ref struct parameter or return type) cannot be rewritten to accessor delegates. An extension method of an `internal` static class applies in either form, because the accessor names the class through typeof, as long as the last compile built that class into the edited assembly and the class is declared in a file this reload passes or pulls back in: one in a class this reload adds or in a file the reload does not see is refused, as is one whose return type the same edit changes, a method of an `internal` class that is not an extension method, or one whose parameter or return types are not public. Neither can ref-returning properties, nor these writes to a property through a private/internal setter: `??=`, a compound write whose receiver could be evaluated twice, an assignment whose value is used (a lambda or `=>` member that returns nothing and is only the assignment applies), and a deconstruction. A compound write (`+=`, `??=`, and the like) to a property whose getter is private/internal and whose setter is not is refused as well. The same writes to a private/internal field declared on a class apply, static fields included. In an async body, such a field is also refused when the expression uses it by reference and awaits after that use: passed as `ref`, `out` or `in`, the receiver of a call that takes it by reference, assigned to (`=`, `+=`, a deconstruction), or a struct field whose member or indexer is assigned, as in `M(ref _count, await GetAsync())` or `_count += await GetAsync()`. This holds whatever the call is, a method added in the same reload included; await into a local first, as in `int value = await GetAsync();`, and use the local. That moves the field's read after the await; when the original order matters, read the field into a local before the await as well: `int count = _count; int value = await GetAsync(); _count = count + value;`. A private/internal instance member declared on a struct is refused. An inaccessible method the compiler calls for `await`, `foreach`, `await foreach`, a deconstruction or positional pattern, a collection initializer, a query expression, an interpolated string handler, an index or range (`^1`, `a..b`), a ref struct's `using`, or `await using` is refused as well, including the awaiter of the value `DisposeAsync` or `MoveNextAsync` returns. These limits apply to compiled members; a method added in the same reload is reached directly, whatever its arguments, except a generic, by-ref-returning, or `[Conditional]` added method, which is refused as a compiled one is. An added extension method called on a receiver, `receiver.Method(...)`, gets the outcome of its static form, `Extensions.Method(receiver, ...)` (`Extensions.Method(ref receiver, ...)` for a `this ref` method), except through conditional access (`receiver?.Method(...)`), which is skipped as every added-method call through `?.` is; write the null check and the static form instead. A compiled private/internal static property can be read, assigned, and compound-assigned | | An async/iterator/closure body of a type not visible outside its assembly reaches a compiled member | An accessor delegate has to name its host, which a shim cannot do for an `internal` class or a class nested in one, so this refuses even a `public` member of that class. A body reaching only methods added in the same reload applies. In a lambda or local function, copy the compiled member into a local outside it; otherwise run `uloop compile` | | An async/iterator/closure body references a private/internal type | Accessor delegates rescue member access, not type references; the body still cannot JIT-compile from the shim assembly. The one exception is the class of a call written in the static form, `Extensions.Method(receiver, ...)`, inside the lambda, local function or async body, when the call itself is rewritten, because the rewritten call no longer names the class | | A declared return or parameter type cannot be resolved (a new type this reload could not introduce, a missing using, or a typo) | Skipped; a supported new type declared in an edited file of the same assembly is introduced by this reload, so check `Warnings` for the refusal reason (`introduced-types.md`); otherwise add the type or the `using`, or fix the typo, then run `uloop compile` | diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/AccessorEntry.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/AccessorEntry.cs index afdb1bd65e..bd8805bac6 100644 --- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/AccessorEntry.cs +++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/AccessorEntry.cs @@ -203,7 +203,11 @@ public FieldDeclarationSyntax EmitFieldDeclaration() /// Mono). On a runtime that did check it, the bind would throw in __BindAccessors, before any /// patch is applied, not after the method was reported patched. ADR 0010 /// (docs/adr/0010-hot-reload-internal-introduced-types.md) reopens Mono-only behavior when the - /// Editor moves to CoreCLR. + /// Editor moves to CoreCLR. Known limit: when a referenced assembly declares a public type with + /// the full name of the class (the target compiles with CS0436 and its own class wins), the + /// typeof is ambiguous in the shim compile (CS0433), so the file's entries are dropped and + /// recompiled, or the file fails; it never binds the wrong class. A public class has the same + /// limit. /// public StatementSyntax EmitBindStatement() { diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/NonPublicExtensionClassBind.cs b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/NonPublicExtensionClassBind.cs index 3344759dd7..29685876e8 100644 --- a/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/NonPublicExtensionClassBind.cs +++ b/Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/NonPublicExtensionClassBind.cs @@ -56,9 +56,9 @@ internal static bool AllowsNonPublicClass(IMethodSymbol method, IAssemblySymbol /// and holds the method with the same return type or not at all. /// /// - /// Why the class must already be compiled: the shim compiles against a copy of that assembly, and - /// a class this reload adds is not there, so the bind's typeof of it would fail the whole file - /// instead of skipping the one method. Why a method this reload adds passes: only its + /// Why the class must already be compiled: a class this reload adds is not in the compiled + /// assembly. Without this check the reload reports the method Patched and its first call throws + /// MethodAccessException from the shim (measured), so the method is skipped instead. Why a method this reload adds passes: only its /// static-form call gets this far, the reduced form being refused before, and the added-method /// rewrite replaces that call, so the shim binds no accessor for it. Why a changed return type /// fails: the bind would find the compiled method by its parameters and could not make a delegate From ce3765b7c0fab1dd09bebece039b5d0406baea87 Mon Sep 17 00:00:00 2001 From: hatayama Date: Sat, 28 Nov 2026 20:55:34 +0900 Subject: [PATCH 4/4] docs: note the same-name type collision for a non-public extension class A referenced assembly that declares a public type with the full name of the extension's class makes the shim's typeof ambiguous (CS0433), so that file's edits are not applied. scope-and-limits.md now says so and how to resolve it; the .claude/ and .agents/ copies are regenerated. --- .agents/skills/uloop-hot-reload/references/scope-and-limits.md | 2 +- .claude/skills/uloop-hot-reload/references/scope-and-limits.md | 2 +- .../HotReload/Skill/references/scope-and-limits.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.agents/skills/uloop-hot-reload/references/scope-and-limits.md b/.agents/skills/uloop-hot-reload/references/scope-and-limits.md index 6dc99723a8..8807c72153 100644 --- a/.agents/skills/uloop-hot-reload/references/scope-and-limits.md +++ b/.agents/skills/uloop-hot-reload/references/scope-and-limits.md @@ -469,7 +469,7 @@ source on disk. When a run skips a method it had patched before, `Warnings` name | Base call to a method marked `[Conditional]` | The compiler removes the call, and the evaluation of its arguments, when the symbol is not defined; hot reload cannot do the same. Run `uloop compile` | | Base call to a method whose base type declares another overload with the same parameter types once its type arguments are filled in (for example `Pick(T)` and `Pick(int)` on `Base`) | Hot reload finds the base method by name and parameter types, which cannot tell these overloads apart. Run `uloop compile` | | Base call to a method the compiled assembly does not hold yet (added or re-signatured since the last compile) | Run `uloop compile` | -| Private/internal access inside an async/iterator/closure body has no accessor-delegate shape | Conditional access (`?.`), indexers, initializer member assignments, a member named in a property pattern (`x is { _count: 0 }`, or a link of `{ A.B: 0 }`; read the same member path outside the pattern instead: `x._count == 0`, `x.A.B == 0`), and calls with `ref`/`out`/`in`, named, omitted optional, or expanded `params` arguments (or to generic, by-ref-returning, or `[Conditional]` methods, or methods with a ref struct parameter or return type) cannot be rewritten to accessor delegates. An extension method of an `internal` static class applies in either form, because the accessor names the class through typeof, as long as the last compile built that class into the edited assembly and the class is declared in a file this reload passes or pulls back in: one in a class this reload adds or in a file the reload does not see is refused, as is one whose return type the same edit changes, a method of an `internal` class that is not an extension method, or one whose parameter or return types are not public. Neither can ref-returning properties, nor these writes to a property through a private/internal setter: `??=`, a compound write whose receiver could be evaluated twice, an assignment whose value is used (a lambda or `=>` member that returns nothing and is only the assignment applies), and a deconstruction. A compound write (`+=`, `??=`, and the like) to a property whose getter is private/internal and whose setter is not is refused as well. The same writes to a private/internal field declared on a class apply, static fields included. In an async body, such a field is also refused when the expression uses it by reference and awaits after that use: passed as `ref`, `out` or `in`, the receiver of a call that takes it by reference, assigned to (`=`, `+=`, a deconstruction), or a struct field whose member or indexer is assigned, as in `M(ref _count, await GetAsync())` or `_count += await GetAsync()`. This holds whatever the call is, a method added in the same reload included; await into a local first, as in `int value = await GetAsync();`, and use the local. That moves the field's read after the await; when the original order matters, read the field into a local before the await as well: `int count = _count; int value = await GetAsync(); _count = count + value;`. A private/internal instance member declared on a struct is refused. An inaccessible method the compiler calls for `await`, `foreach`, `await foreach`, a deconstruction or positional pattern, a collection initializer, a query expression, an interpolated string handler, an index or range (`^1`, `a..b`), a ref struct's `using`, or `await using` is refused as well, including the awaiter of the value `DisposeAsync` or `MoveNextAsync` returns. These limits apply to compiled members; a method added in the same reload is reached directly, whatever its arguments, except a generic, by-ref-returning, or `[Conditional]` added method, which is refused as a compiled one is. An added extension method called on a receiver, `receiver.Method(...)`, gets the outcome of its static form, `Extensions.Method(receiver, ...)` (`Extensions.Method(ref receiver, ...)` for a `this ref` method), except through conditional access (`receiver?.Method(...)`), which is skipped as every added-method call through `?.` is; write the null check and the static form instead. A compiled private/internal static property can be read, assigned, and compound-assigned | +| Private/internal access inside an async/iterator/closure body has no accessor-delegate shape | Conditional access (`?.`), indexers, initializer member assignments, a member named in a property pattern (`x is { _count: 0 }`, or a link of `{ A.B: 0 }`; read the same member path outside the pattern instead: `x._count == 0`, `x.A.B == 0`), and calls with `ref`/`out`/`in`, named, omitted optional, or expanded `params` arguments (or to generic, by-ref-returning, or `[Conditional]` methods, or methods with a ref struct parameter or return type) cannot be rewritten to accessor delegates. An extension method of an `internal` static class applies in either form, because the accessor names the class through typeof, as long as the last compile built that class into the edited assembly and the class is declared in a file this reload passes or pulls back in: one in a class this reload adds or in a file the reload does not see is refused, as is one whose return type the same edit changes, a method of an `internal` class that is not an extension method, or one whose parameter or return types are not public. When an assembly the edited one references declares a public type with the same full name as the extension's class, the shim cannot tell the two apart (CS0433) and that file's edits are not applied; give one of the types another name. Neither can ref-returning properties, nor these writes to a property through a private/internal setter: `??=`, a compound write whose receiver could be evaluated twice, an assignment whose value is used (a lambda or `=>` member that returns nothing and is only the assignment applies), and a deconstruction. A compound write (`+=`, `??=`, and the like) to a property whose getter is private/internal and whose setter is not is refused as well. The same writes to a private/internal field declared on a class apply, static fields included. In an async body, such a field is also refused when the expression uses it by reference and awaits after that use: passed as `ref`, `out` or `in`, the receiver of a call that takes it by reference, assigned to (`=`, `+=`, a deconstruction), or a struct field whose member or indexer is assigned, as in `M(ref _count, await GetAsync())` or `_count += await GetAsync()`. This holds whatever the call is, a method added in the same reload included; await into a local first, as in `int value = await GetAsync();`, and use the local. That moves the field's read after the await; when the original order matters, read the field into a local before the await as well: `int count = _count; int value = await GetAsync(); _count = count + value;`. A private/internal instance member declared on a struct is refused. An inaccessible method the compiler calls for `await`, `foreach`, `await foreach`, a deconstruction or positional pattern, a collection initializer, a query expression, an interpolated string handler, an index or range (`^1`, `a..b`), a ref struct's `using`, or `await using` is refused as well, including the awaiter of the value `DisposeAsync` or `MoveNextAsync` returns. These limits apply to compiled members; a method added in the same reload is reached directly, whatever its arguments, except a generic, by-ref-returning, or `[Conditional]` added method, which is refused as a compiled one is. An added extension method called on a receiver, `receiver.Method(...)`, gets the outcome of its static form, `Extensions.Method(receiver, ...)` (`Extensions.Method(ref receiver, ...)` for a `this ref` method), except through conditional access (`receiver?.Method(...)`), which is skipped as every added-method call through `?.` is; write the null check and the static form instead. A compiled private/internal static property can be read, assigned, and compound-assigned | | An async/iterator/closure body of a type not visible outside its assembly reaches a compiled member | An accessor delegate has to name its host, which a shim cannot do for an `internal` class or a class nested in one, so this refuses even a `public` member of that class. A body reaching only methods added in the same reload applies. In a lambda or local function, copy the compiled member into a local outside it; otherwise run `uloop compile` | | An async/iterator/closure body references a private/internal type | Accessor delegates rescue member access, not type references; the body still cannot JIT-compile from the shim assembly. The one exception is the class of a call written in the static form, `Extensions.Method(receiver, ...)`, inside the lambda, local function or async body, when the call itself is rewritten, because the rewritten call no longer names the class | | A declared return or parameter type cannot be resolved (a new type this reload could not introduce, a missing using, or a typo) | Skipped; a supported new type declared in an edited file of the same assembly is introduced by this reload, so check `Warnings` for the refusal reason (`introduced-types.md`); otherwise add the type or the `using`, or fix the typo, then run `uloop compile` | diff --git a/.claude/skills/uloop-hot-reload/references/scope-and-limits.md b/.claude/skills/uloop-hot-reload/references/scope-and-limits.md index 6dc99723a8..8807c72153 100644 --- a/.claude/skills/uloop-hot-reload/references/scope-and-limits.md +++ b/.claude/skills/uloop-hot-reload/references/scope-and-limits.md @@ -469,7 +469,7 @@ source on disk. When a run skips a method it had patched before, `Warnings` name | Base call to a method marked `[Conditional]` | The compiler removes the call, and the evaluation of its arguments, when the symbol is not defined; hot reload cannot do the same. Run `uloop compile` | | Base call to a method whose base type declares another overload with the same parameter types once its type arguments are filled in (for example `Pick(T)` and `Pick(int)` on `Base`) | Hot reload finds the base method by name and parameter types, which cannot tell these overloads apart. Run `uloop compile` | | Base call to a method the compiled assembly does not hold yet (added or re-signatured since the last compile) | Run `uloop compile` | -| Private/internal access inside an async/iterator/closure body has no accessor-delegate shape | Conditional access (`?.`), indexers, initializer member assignments, a member named in a property pattern (`x is { _count: 0 }`, or a link of `{ A.B: 0 }`; read the same member path outside the pattern instead: `x._count == 0`, `x.A.B == 0`), and calls with `ref`/`out`/`in`, named, omitted optional, or expanded `params` arguments (or to generic, by-ref-returning, or `[Conditional]` methods, or methods with a ref struct parameter or return type) cannot be rewritten to accessor delegates. An extension method of an `internal` static class applies in either form, because the accessor names the class through typeof, as long as the last compile built that class into the edited assembly and the class is declared in a file this reload passes or pulls back in: one in a class this reload adds or in a file the reload does not see is refused, as is one whose return type the same edit changes, a method of an `internal` class that is not an extension method, or one whose parameter or return types are not public. Neither can ref-returning properties, nor these writes to a property through a private/internal setter: `??=`, a compound write whose receiver could be evaluated twice, an assignment whose value is used (a lambda or `=>` member that returns nothing and is only the assignment applies), and a deconstruction. A compound write (`+=`, `??=`, and the like) to a property whose getter is private/internal and whose setter is not is refused as well. The same writes to a private/internal field declared on a class apply, static fields included. In an async body, such a field is also refused when the expression uses it by reference and awaits after that use: passed as `ref`, `out` or `in`, the receiver of a call that takes it by reference, assigned to (`=`, `+=`, a deconstruction), or a struct field whose member or indexer is assigned, as in `M(ref _count, await GetAsync())` or `_count += await GetAsync()`. This holds whatever the call is, a method added in the same reload included; await into a local first, as in `int value = await GetAsync();`, and use the local. That moves the field's read after the await; when the original order matters, read the field into a local before the await as well: `int count = _count; int value = await GetAsync(); _count = count + value;`. A private/internal instance member declared on a struct is refused. An inaccessible method the compiler calls for `await`, `foreach`, `await foreach`, a deconstruction or positional pattern, a collection initializer, a query expression, an interpolated string handler, an index or range (`^1`, `a..b`), a ref struct's `using`, or `await using` is refused as well, including the awaiter of the value `DisposeAsync` or `MoveNextAsync` returns. These limits apply to compiled members; a method added in the same reload is reached directly, whatever its arguments, except a generic, by-ref-returning, or `[Conditional]` added method, which is refused as a compiled one is. An added extension method called on a receiver, `receiver.Method(...)`, gets the outcome of its static form, `Extensions.Method(receiver, ...)` (`Extensions.Method(ref receiver, ...)` for a `this ref` method), except through conditional access (`receiver?.Method(...)`), which is skipped as every added-method call through `?.` is; write the null check and the static form instead. A compiled private/internal static property can be read, assigned, and compound-assigned | +| Private/internal access inside an async/iterator/closure body has no accessor-delegate shape | Conditional access (`?.`), indexers, initializer member assignments, a member named in a property pattern (`x is { _count: 0 }`, or a link of `{ A.B: 0 }`; read the same member path outside the pattern instead: `x._count == 0`, `x.A.B == 0`), and calls with `ref`/`out`/`in`, named, omitted optional, or expanded `params` arguments (or to generic, by-ref-returning, or `[Conditional]` methods, or methods with a ref struct parameter or return type) cannot be rewritten to accessor delegates. An extension method of an `internal` static class applies in either form, because the accessor names the class through typeof, as long as the last compile built that class into the edited assembly and the class is declared in a file this reload passes or pulls back in: one in a class this reload adds or in a file the reload does not see is refused, as is one whose return type the same edit changes, a method of an `internal` class that is not an extension method, or one whose parameter or return types are not public. When an assembly the edited one references declares a public type with the same full name as the extension's class, the shim cannot tell the two apart (CS0433) and that file's edits are not applied; give one of the types another name. Neither can ref-returning properties, nor these writes to a property through a private/internal setter: `??=`, a compound write whose receiver could be evaluated twice, an assignment whose value is used (a lambda or `=>` member that returns nothing and is only the assignment applies), and a deconstruction. A compound write (`+=`, `??=`, and the like) to a property whose getter is private/internal and whose setter is not is refused as well. The same writes to a private/internal field declared on a class apply, static fields included. In an async body, such a field is also refused when the expression uses it by reference and awaits after that use: passed as `ref`, `out` or `in`, the receiver of a call that takes it by reference, assigned to (`=`, `+=`, a deconstruction), or a struct field whose member or indexer is assigned, as in `M(ref _count, await GetAsync())` or `_count += await GetAsync()`. This holds whatever the call is, a method added in the same reload included; await into a local first, as in `int value = await GetAsync();`, and use the local. That moves the field's read after the await; when the original order matters, read the field into a local before the await as well: `int count = _count; int value = await GetAsync(); _count = count + value;`. A private/internal instance member declared on a struct is refused. An inaccessible method the compiler calls for `await`, `foreach`, `await foreach`, a deconstruction or positional pattern, a collection initializer, a query expression, an interpolated string handler, an index or range (`^1`, `a..b`), a ref struct's `using`, or `await using` is refused as well, including the awaiter of the value `DisposeAsync` or `MoveNextAsync` returns. These limits apply to compiled members; a method added in the same reload is reached directly, whatever its arguments, except a generic, by-ref-returning, or `[Conditional]` added method, which is refused as a compiled one is. An added extension method called on a receiver, `receiver.Method(...)`, gets the outcome of its static form, `Extensions.Method(receiver, ...)` (`Extensions.Method(ref receiver, ...)` for a `this ref` method), except through conditional access (`receiver?.Method(...)`), which is skipped as every added-method call through `?.` is; write the null check and the static form instead. A compiled private/internal static property can be read, assigned, and compound-assigned | | An async/iterator/closure body of a type not visible outside its assembly reaches a compiled member | An accessor delegate has to name its host, which a shim cannot do for an `internal` class or a class nested in one, so this refuses even a `public` member of that class. A body reaching only methods added in the same reload applies. In a lambda or local function, copy the compiled member into a local outside it; otherwise run `uloop compile` | | An async/iterator/closure body references a private/internal type | Accessor delegates rescue member access, not type references; the body still cannot JIT-compile from the shim assembly. The one exception is the class of a call written in the static form, `Extensions.Method(receiver, ...)`, inside the lambda, local function or async body, when the call itself is rewritten, because the rewritten call no longer names the class | | A declared return or parameter type cannot be resolved (a new type this reload could not introduce, a missing using, or a typo) | Skipped; a supported new type declared in an edited file of the same assembly is introduced by this reload, so check `Warnings` for the refusal reason (`introduced-types.md`); otherwise add the type or the `using`, or fix the typo, then run `uloop compile` | diff --git a/Packages/src/Editor/FirstPartyTools/HotReload/Skill/references/scope-and-limits.md b/Packages/src/Editor/FirstPartyTools/HotReload/Skill/references/scope-and-limits.md index 6dc99723a8..8807c72153 100644 --- a/Packages/src/Editor/FirstPartyTools/HotReload/Skill/references/scope-and-limits.md +++ b/Packages/src/Editor/FirstPartyTools/HotReload/Skill/references/scope-and-limits.md @@ -469,7 +469,7 @@ source on disk. When a run skips a method it had patched before, `Warnings` name | Base call to a method marked `[Conditional]` | The compiler removes the call, and the evaluation of its arguments, when the symbol is not defined; hot reload cannot do the same. Run `uloop compile` | | Base call to a method whose base type declares another overload with the same parameter types once its type arguments are filled in (for example `Pick(T)` and `Pick(int)` on `Base`) | Hot reload finds the base method by name and parameter types, which cannot tell these overloads apart. Run `uloop compile` | | Base call to a method the compiled assembly does not hold yet (added or re-signatured since the last compile) | Run `uloop compile` | -| Private/internal access inside an async/iterator/closure body has no accessor-delegate shape | Conditional access (`?.`), indexers, initializer member assignments, a member named in a property pattern (`x is { _count: 0 }`, or a link of `{ A.B: 0 }`; read the same member path outside the pattern instead: `x._count == 0`, `x.A.B == 0`), and calls with `ref`/`out`/`in`, named, omitted optional, or expanded `params` arguments (or to generic, by-ref-returning, or `[Conditional]` methods, or methods with a ref struct parameter or return type) cannot be rewritten to accessor delegates. An extension method of an `internal` static class applies in either form, because the accessor names the class through typeof, as long as the last compile built that class into the edited assembly and the class is declared in a file this reload passes or pulls back in: one in a class this reload adds or in a file the reload does not see is refused, as is one whose return type the same edit changes, a method of an `internal` class that is not an extension method, or one whose parameter or return types are not public. Neither can ref-returning properties, nor these writes to a property through a private/internal setter: `??=`, a compound write whose receiver could be evaluated twice, an assignment whose value is used (a lambda or `=>` member that returns nothing and is only the assignment applies), and a deconstruction. A compound write (`+=`, `??=`, and the like) to a property whose getter is private/internal and whose setter is not is refused as well. The same writes to a private/internal field declared on a class apply, static fields included. In an async body, such a field is also refused when the expression uses it by reference and awaits after that use: passed as `ref`, `out` or `in`, the receiver of a call that takes it by reference, assigned to (`=`, `+=`, a deconstruction), or a struct field whose member or indexer is assigned, as in `M(ref _count, await GetAsync())` or `_count += await GetAsync()`. This holds whatever the call is, a method added in the same reload included; await into a local first, as in `int value = await GetAsync();`, and use the local. That moves the field's read after the await; when the original order matters, read the field into a local before the await as well: `int count = _count; int value = await GetAsync(); _count = count + value;`. A private/internal instance member declared on a struct is refused. An inaccessible method the compiler calls for `await`, `foreach`, `await foreach`, a deconstruction or positional pattern, a collection initializer, a query expression, an interpolated string handler, an index or range (`^1`, `a..b`), a ref struct's `using`, or `await using` is refused as well, including the awaiter of the value `DisposeAsync` or `MoveNextAsync` returns. These limits apply to compiled members; a method added in the same reload is reached directly, whatever its arguments, except a generic, by-ref-returning, or `[Conditional]` added method, which is refused as a compiled one is. An added extension method called on a receiver, `receiver.Method(...)`, gets the outcome of its static form, `Extensions.Method(receiver, ...)` (`Extensions.Method(ref receiver, ...)` for a `this ref` method), except through conditional access (`receiver?.Method(...)`), which is skipped as every added-method call through `?.` is; write the null check and the static form instead. A compiled private/internal static property can be read, assigned, and compound-assigned | +| Private/internal access inside an async/iterator/closure body has no accessor-delegate shape | Conditional access (`?.`), indexers, initializer member assignments, a member named in a property pattern (`x is { _count: 0 }`, or a link of `{ A.B: 0 }`; read the same member path outside the pattern instead: `x._count == 0`, `x.A.B == 0`), and calls with `ref`/`out`/`in`, named, omitted optional, or expanded `params` arguments (or to generic, by-ref-returning, or `[Conditional]` methods, or methods with a ref struct parameter or return type) cannot be rewritten to accessor delegates. An extension method of an `internal` static class applies in either form, because the accessor names the class through typeof, as long as the last compile built that class into the edited assembly and the class is declared in a file this reload passes or pulls back in: one in a class this reload adds or in a file the reload does not see is refused, as is one whose return type the same edit changes, a method of an `internal` class that is not an extension method, or one whose parameter or return types are not public. When an assembly the edited one references declares a public type with the same full name as the extension's class, the shim cannot tell the two apart (CS0433) and that file's edits are not applied; give one of the types another name. Neither can ref-returning properties, nor these writes to a property through a private/internal setter: `??=`, a compound write whose receiver could be evaluated twice, an assignment whose value is used (a lambda or `=>` member that returns nothing and is only the assignment applies), and a deconstruction. A compound write (`+=`, `??=`, and the like) to a property whose getter is private/internal and whose setter is not is refused as well. The same writes to a private/internal field declared on a class apply, static fields included. In an async body, such a field is also refused when the expression uses it by reference and awaits after that use: passed as `ref`, `out` or `in`, the receiver of a call that takes it by reference, assigned to (`=`, `+=`, a deconstruction), or a struct field whose member or indexer is assigned, as in `M(ref _count, await GetAsync())` or `_count += await GetAsync()`. This holds whatever the call is, a method added in the same reload included; await into a local first, as in `int value = await GetAsync();`, and use the local. That moves the field's read after the await; when the original order matters, read the field into a local before the await as well: `int count = _count; int value = await GetAsync(); _count = count + value;`. A private/internal instance member declared on a struct is refused. An inaccessible method the compiler calls for `await`, `foreach`, `await foreach`, a deconstruction or positional pattern, a collection initializer, a query expression, an interpolated string handler, an index or range (`^1`, `a..b`), a ref struct's `using`, or `await using` is refused as well, including the awaiter of the value `DisposeAsync` or `MoveNextAsync` returns. These limits apply to compiled members; a method added in the same reload is reached directly, whatever its arguments, except a generic, by-ref-returning, or `[Conditional]` added method, which is refused as a compiled one is. An added extension method called on a receiver, `receiver.Method(...)`, gets the outcome of its static form, `Extensions.Method(receiver, ...)` (`Extensions.Method(ref receiver, ...)` for a `this ref` method), except through conditional access (`receiver?.Method(...)`), which is skipped as every added-method call through `?.` is; write the null check and the static form instead. A compiled private/internal static property can be read, assigned, and compound-assigned | | An async/iterator/closure body of a type not visible outside its assembly reaches a compiled member | An accessor delegate has to name its host, which a shim cannot do for an `internal` class or a class nested in one, so this refuses even a `public` member of that class. A body reaching only methods added in the same reload applies. In a lambda or local function, copy the compiled member into a local outside it; otherwise run `uloop compile` | | An async/iterator/closure body references a private/internal type | Accessor delegates rescue member access, not type references; the body still cannot JIT-compile from the shim assembly. The one exception is the class of a call written in the static form, `Extensions.Method(receiver, ...)`, inside the lambda, local function or async body, when the call itself is rewritten, because the rewritten call no longer names the class | | A declared return or parameter type cannot be resolved (a new type this reload could not introduce, a missing using, or a typo) | Skipped; a supported new type declared in an edited file of the same assembly is introduced by this reload, so check `Warnings` for the refusal reason (`introduced-types.md`); otherwise add the type or the `using`, or fix the typo, then run `uloop compile` |