[
https://issues.apache.org/jira/browse/THRIFT-5997?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Jens Geyer updated THRIFT-5997:
-------------------------------
Component/s: netstd - Compiler
> netstd generator: binary and uuid constants emitted as C# const instead of
> static readonly
> ------------------------------------------------------------------------------------------
>
> Key: THRIFT-5997
> URL: https://issues.apache.org/jira/browse/THRIFT-5997
> Project: Thrift
> Issue Type: Bug
> Components: netcore - Library, netstd - Compiler
> Reporter: Jens Geyer
> Priority: Major
>
> The netstd code generator declares all Thrift {{const}} fields of base types
> using the C# {{const}} keyword ({{print_const_value}}, line ~619). Two base
> types cannot legally be C# {{const}}:
> 1. *binary* maps to {{byte[]}} in C#. Arrays are reference types and cannot
> be {{const}}. The generated code calls
> {{System.Text.Encoding.UTF8.GetBytes("...")}} as the initialiser, which is a
> runtime expression, not a compile-time constant. This produces CS0133
> ("expression must be constant").
> 2. *uuid* maps to {{System.Guid}} in C#. {{Guid}} is a struct, but it is not
> one of the primitive types recognised by C# as a constant type (bool, char,
> numerics, string, enums). The generated {{new System.Guid("...")}}
> initialiser is also a runtime call. This produces both CS0283 ("type Guid
> cannot be declared as const") and CS0133.
> Fix: in {{print_const_value()}}, detect {{is_binary()}} and {{TYPE_UUID}} and
> emit {{public static readonly}} instead of {{public const}} for those two
> cases. The initialiser expression remains unchanged — it is legal for
> {{static readonly}} fields.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)