Skip to content

Commit 3d6dd31

Browse files
committed
fix: hashes now return number instead of number | hash
1 parent 98ae0cf commit 3d6dd31

3 files changed

Lines changed: 6 additions & 5 deletions

File tree

src/NativeCodeGen.Core/Generation/ITypeMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public interface ITypeMapper
1010
/// <summary>
1111
/// Maps a C type to the target language type.
1212
/// </summary>
13-
string MapType(TypeInfo type, bool isNotNull = false);
13+
string MapType(TypeInfo type, bool isNotNull = false, bool forReturn = false);
1414

1515
/// <summary>
1616
/// Gets the expression for marking a return type in native invocation.

src/NativeCodeGen.Core/Generation/RawNativeBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ private string MapReturnType(TypeInfo type)
391391
if (type.Category == TypeCategory.Vector3)
392392
return _config.Vector3Type;
393393

394-
return _typeMapper.MapType(type);
394+
return _typeMapper.MapType(type, forReturn: true);
395395
}
396396

397397
private string MapOutputType(TypeInfo type)

src/NativeCodeGen.Core/TypeSystem/TypeMapperBase.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ protected TypeMapperBase(LanguageConfig config)
120120
Config = config;
121121
}
122122

123-
public virtual string MapType(TypeInfo type, bool isNotNull = false)
123+
public virtual string MapType(TypeInfo type, bool isNotNull = false, bool forReturn = false)
124124
{
125125
if (type.IsPointer)
126126
{
@@ -142,7 +142,8 @@ public virtual string MapType(TypeInfo type, bool isNotNull = false)
142142
TypeCategory.Handle => Config.UseTypedHandles && TypeInfo.IsClassHandle(type.Name)
143143
? (type.Name == "Object" ? "Prop" : type.Name)
144144
: Config.NumberType,
145-
TypeCategory.Hash => Config.HashType,
145+
// Hash parameters accept string | number, but return type is always number
146+
TypeCategory.Hash => forReturn ? Config.NumberType : Config.HashType,
146147
TypeCategory.String => isNotNull ? Config.StringType : Config.StringType + Config.NullableStringSuffix,
147148
TypeCategory.Vector2 => Config.Vector2Type,
148149
TypeCategory.Vector3 => Config.Vector3Type,
@@ -298,7 +299,7 @@ public virtual string BuildCombinedReturnType(TypeInfo returnType, IEnumerable<T
298299
// Helper to add nullable suffix for class handle return types
299300
string MapReturnType(TypeInfo type)
300301
{
301-
var mapped = MapType(type);
302+
var mapped = MapType(type, forReturn: true);
302303
// Class handle return types can be null (invalid handle returns 0)
303304
// Non-class handles (Prompt, ScrHandle) are just numbers
304305
if (type.Category == TypeCategory.Handle && Config.UseTypedHandles && TypeInfo.IsClassHandle(type.Name))

0 commit comments

Comments
 (0)