FastScriptReload icon indicating copy to clipboard operation
FastScriptReload copied to clipboard

Add support to reload modules with Unity's IsExternalInit workaround to C# records

Open vlevykin opened this issue 2 years ago • 3 comments

Unity has limited support to C# records and init only setters, but Unity documentation suggests to manually declare IsExternalInit class: https://docs.unity3d.com/2021.2/Documentation/Manual/CSharpCompiler.html

We use this approach in project and it works, but FastScriptReload fails to reload such modules, outputs such errors:

046412b42d9540adb22c28aa3d99dce9.SourceCodeCombined.cs(26,25): error CS0518: Predefined type 'System.Runtime.CompilerServices.IsExternalInit' is not defined or imported

Looks like it is possible to use same approach (adding IsExternalInit class) with temporary files compilation. Is there a possibility to reload such code?

vlevykin avatar Nov 29 '23 03:11 vlevykin

Hi, I'm not quite sure, never worked with records.

If you can add an small example to recreate then I may be able to help.

handzlikchris avatar Dec 01 '23 08:12 handzlikchris

Well, related is an issue with records indeed, does not seem to add a patch id on the class name. Init syntax can be replaced with this syntax btw.

Could it work with records in the end or should we take into account it won't in the shortcoming ? We started to move things into records because of the added sugar on copy ctors/parameter delcaration/init etc

    public record AttackScorePosition(IReadOnlyList<AttackRangeResults> Results, Optional<PathResult> OptPath, int Score) : IScore<CharacterPosition, int>, IHasSkillResult
    {
        
        /// <summary>
        /// Attack score without result
        /// </summary>
        public AttackScorePosition__Patched_() : this(new List<AttackRangeResults>(),Optional<PathResult>.Empty() , 0)
        {

        }

builder-main avatar Dec 01 '23 13:12 builder-main

Also, it seems that it is not an issue with records themselves but with those using the shortcut syntax, like the one above.

builder-main avatar Dec 01 '23 17:12 builder-main