How can I pass world position to a custom lighting function for a surface shader?

I’m trying to use world position ton a custom lighting function, passed to the lighting function via a custom surface output struct. However, every time it fails to compile and claims the surface output custom struct is not initialized. However, this is clearly not the case and appears that something else is going on behind the scenes. I’ve included a much stripped down shader that reproduces the error and have marked exactly where it fails at compiling.

However, note that if you perform any sort of operation (o.posWorld = IN.worldPos * 1.0;) on it it will compile, but then fail to compile if you use o.posWorld anywhere in the lighting function.

Shader "Custom/TestUnityAnswers" 
{
    Properties 
    {
        _MainTex ("Diffuse RGB", 2D) = "white" {}
    }

    SubShader 
    {
    	Tags { "RenderType" = "Opaque" }
        LOD 200
        CGPROGRAM
		// Upgrade NOTE: excluded shader from OpenGL ES 2.0 because it does not contain a surface program or both vertex and fragment programs.
		#pragma exclude_renderers gles
		#pragma only_renderers d3d11
        #pragma vertex vert 
        #pragma surface surf Lambert2
        sampler2D _MainTex;
        
        struct Input 
        {
			float2 uv_MainTex : TEXCOORD0;
			float3 worldPos   : TEXCOORD1;
		};
	
		struct SurfaceOutputCustom 
		{
			fixed3 Albedo;
			fixed3 Normal;
			fixed3 Emission;
			half Specular;
			fixed Gloss;
			fixed Alpha;
			fixed3 posWorld;
		};
		
		void vert (inout appdata_full v, out Input o) 
		{
			UNITY_INITIALIZE_OUTPUT(Input,o);
			o.worldPos = mul(_Object2World, v.vertex).xyz;
		}

	    inline fixed4 LightingLambert2 (SurfaceOutputCustom s, fixed3 lightDir, fixed atten) 
	    {
	        fixed4 c;
	        fixed diff = max (0, dot (s.Normal, lightDir));
	        c.rgb = s.Albedo * _LightColor0.rgb * diff * atten * 2;
	        c.a = s.Alpha;
	        return c;
	    }
	    
        void surf (Input IN, inout SurfaceOutputCustom o) 
        {
            fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
            o.Albedo = tex.rgb; 
            
            // Offending line
            o.posWorld = IN.worldPos;
        }

        ENDCG
    }
}

Calling in from 2019, seems that this use-case works fine these days.
This code displays world position from the custom lighting model.

Shader "Custom/TestUnityAnswers"
{
	Properties
	{
		_MainTex("Diffuse RGB", 2D) = "white" {}
	}

		SubShader
	{
		Tags { "RenderType" = "Opaque" }
		LOD 200
		CGPROGRAM
		#pragma exclude_renderers gles
		#pragma only_renderers d3d11
		#pragma vertex vert 
		#pragma surface surf Lambert2
		sampler2D _MainTex;

		struct Input
		{
			float2 uv_MainTex : TEXCOORD0;
			float3 worldPos   : TEXCOORD1;
		};

		struct SurfaceOutputCustom
		{
			fixed3 Albedo;
			fixed3 Normal;
			fixed3 Emission;
			half Specular;
			fixed Gloss;
			fixed Alpha;
			fixed3 posWorld;
		};

		void vert(inout appdata_full v, out Input o)
		{
			UNITY_INITIALIZE_OUTPUT(Input,o);
			o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
		}

		inline fixed4 LightingLambert2(SurfaceOutputCustom s, fixed3 lightDir, fixed atten)
		{
			return half4(s.posWorld, 1);
		}

		void surf(Input IN, inout SurfaceOutputCustom o)
		{
			fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
			o.Albedo = tex.rgb;
			o.posWorld = IN.worldPos;
		}

		ENDCG
	}
}