Skip to content

Commit

Permalink
fix error message (neo-project#854)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim8y committed Jan 4, 2024
1 parent 065f04d commit 8fdc94d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/Neo.Compiler.CSharp/DiagnosticId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ static class DiagnosticId
public const string InvalidMethodName = "NC3002";
public const string MethodNameConflict = "NC3003";
public const string EventNameConflict = "NC3004";
public const string InvalidInitialValue = "NC3005";
}
}
37 changes: 22 additions & 15 deletions src/Neo.Compiler.CSharp/MethodConvert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,22 +339,29 @@ private void ProcessFieldInitializer(SemanticModel model, IFieldSymbol field, Ac
preInitialize?.Invoke();
string value = (string)initialValue.ConstructorArguments[0].Value!;
ContractParameterType type = (ContractParameterType)initialValue.ConstructorArguments[1].Value!;
switch (type)
try
{
case ContractParameterType.String:
Push(value);
break;
case ContractParameterType.ByteArray:
Push(value.HexToBytes(true));
break;
case ContractParameterType.Hash160:
Push((UInt160.TryParse(value, out var hash) ? hash : value.ToScriptHash(context.Options.AddressVersion)).ToArray());
break;
case ContractParameterType.PublicKey:
Push(ECPoint.Parse(value, ECCurve.Secp256r1).EncodePoint(true));
break;
default:
throw new CompilationException(field, DiagnosticId.InvalidInitialValueType, $"Unsupported initial value type: {type}");
switch (type)
{
case ContractParameterType.String:
Push(value);
break;
case ContractParameterType.ByteArray:
Push(value.HexToBytes(true));
break;
case ContractParameterType.Hash160:
Push((UInt160.TryParse(value, out var hash) ? hash : value.ToScriptHash(context.Options.AddressVersion)).ToArray());
break;
case ContractParameterType.PublicKey:
Push(ECPoint.Parse(value, ECCurve.Secp256r1).EncodePoint(true));
break;
default:
throw new CompilationException(field, DiagnosticId.InvalidInitialValueType, $"Unsupported initial value type: {type}");
}
}
catch (Exception ex) when (ex is not CompilationException)
{
throw new CompilationException(field, DiagnosticId.InvalidInitialValue, $"Invalid initial value: {value} of type: {type}");
}
postInitialize?.Invoke();
}
Expand Down

0 comments on commit 8fdc94d

Please sign in to comment.