@@ -77,13 +77,28 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
77
77
}
78
78
var cases = ImmutableArray . CreateBuilder < UnionCase > ( ) ;
79
79
var AnyGeneric = false ;
80
+ var variant_names = new HashSet < string > ( ) ;
80
81
foreach ( var ( template , _) in Templates )
81
82
{
82
83
foreach ( var ( member , i ) in template . Members . Select ( ( a , b ) => ( a , b ) ) )
83
84
{
84
85
if ( member is MethodDeclarationSyntax mds )
85
86
{
86
87
var case_name = mds . Identifier . ToString ( ) ;
88
+ if ( ! variant_names . Add ( case_name ) )
89
+ {
90
+ var desc = Utils . MakeError ( Id ,
91
+ Strings . Get ( "Generator.Union.Error.RecordOverloaded" ) ) ;
92
+ if ( member is BaseTypeDeclarationSyntax bts )
93
+ {
94
+ diagnostics . Add ( Diagnostic . Create ( desc , bts . Identifier . GetLocation ( ) ) ) ;
95
+ }
96
+ else
97
+ {
98
+ diagnostics . Add ( Diagnostic . Create ( desc , member . GetLocation ( ) ) ) ;
99
+ }
100
+ continue ;
101
+ }
87
102
var member_symbol = ( IMethodSymbol ) semantic_model . GetDeclaredSymbol ( mds ) ! ;
88
103
var ret_type_symbol = member_symbol . ReturnType ;
89
104
var is_void = ret_type_symbol . SpecialType == SpecialType . System_Void ;
@@ -246,7 +261,23 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
246
261
}
247
262
}
248
263
}
249
- items . Add ( new RecordItem ( type_name , arg_name , kind , is_generic ) ) ;
264
+ var is_enum = type_symbol is { TypeKind : TypeKind . Enum } ;
265
+ var defv = parameter . HasExplicitDefaultValue
266
+ ? is_enum
267
+ ? $ "({ type_name } ){ parameter . ExplicitDefaultValue } "
268
+ : parameter . ExplicitDefaultValue switch
269
+ {
270
+ null => "default" ,
271
+ bool v => v ? "true" : "false" ,
272
+ string v => $ "\" { v . Replace ( "\" " , "\\ \" " ) } \" ",
273
+ ( byte or sbyte or short or ushort or int or uint or long or ulong or double ) and var v
274
+ => $ "{ v } ",
275
+ float v => $ "{ v } f",
276
+ decimal v => $ "{ v } m",
277
+ var v => $ "({ type_name } ){ v } ",
278
+ }
279
+ : null ;
280
+ items . Add ( new RecordItem ( type_name , arg_name , kind , is_generic , defv ) ) ;
250
281
}
251
282
var meta = new RecordMeta ( union_attr . ViewName ) ;
252
283
if ( variant_attr != null )
0 commit comments