diff --git a/Packages/com.merlin.UdonSharp/Editor/Compiler/Binder/BinderSyntaxVisitor.cs b/Packages/com.merlin.UdonSharp/Editor/Compiler/Binder/BinderSyntaxVisitor.cs index 3892a3b7..e1978d8d 100644 --- a/Packages/com.merlin.UdonSharp/Editor/Compiler/Binder/BinderSyntaxVisitor.cs +++ b/Packages/com.merlin.UdonSharp/Editor/Compiler/Binder/BinderSyntaxVisitor.cs @@ -244,6 +244,16 @@ public override BoundNode VisitThrowExpression(ThrowExpressionSyntax node) throw new NotSupportedException("UdonSharp does not support throwing exceptions since Udon does not have support for exception throwing at the moment", node); } + public override BoundNode VisitConstructorDeclaration(ConstructorDeclarationSyntax node) + { + if (node.ExpressionBody is ArrowExpressionClauseSyntax arrowExpressionClause) + { + return VisitArrowExpressionClause(arrowExpressionClause); + } + + return VisitBlock(node.Body); + } + public override BoundNode VisitArrowExpressionClause(ArrowExpressionClauseSyntax node) { return VisitExpression(node.Expression); diff --git a/Packages/com.merlin.UdonSharp/Editor/Compiler/Binder/Symbols/MethodSymbol.cs b/Packages/com.merlin.UdonSharp/Editor/Compiler/Binder/Symbols/MethodSymbol.cs index 4334255d..49d561ca 100644 --- a/Packages/com.merlin.UdonSharp/Editor/Compiler/Binder/Symbols/MethodSymbol.cs +++ b/Packages/com.merlin.UdonSharp/Editor/Compiler/Binder/Symbols/MethodSymbol.cs @@ -204,7 +204,7 @@ public override void Bind(BindContext context) } else if (declaringSyntax is ConstructorDeclarationSyntax constructorDeclaration) { - MethodBody = bodyVisitor.Visit(constructorDeclaration.Body); + MethodBody = bodyVisitor.VisitConstructorDeclaration(constructorDeclaration); } else { diff --git a/Packages/com.merlin.UdonSharp/Runtime/UdonSharpRuntimeUtils.cs b/Packages/com.merlin.UdonSharp/Runtime/UdonSharpRuntimeUtils.cs index aa282895..1cfb6ddd 100644 --- a/Packages/com.merlin.UdonSharp/Runtime/UdonSharpRuntimeUtils.cs +++ b/Packages/com.merlin.UdonSharp/Runtime/UdonSharpRuntimeUtils.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Runtime.CompilerServices; using System.Security.Cryptography; using System.Text; @@ -11,28 +11,34 @@ namespace Internal { public static class UdonSharpInternalUtility { - public static long GetTypeID(System.Type type) + public static long GetTypeID(Type type) { return GetTypeID(type.FullName); } - - public static long GetTypeID(string typeName) + + public static long GetTypeID(string fullTypeName) { - SHA256 typeHash = new SHA256CryptoServiceProvider(); - byte[] hash = typeHash.ComputeHash(Encoding.UTF8.GetBytes(typeName)); - return BitConverter.ToInt64(hash, 0); + // the documentation recommends against utilizing SHA256CryptoServiceProvider + // but the Create method of the base type instead. + + // the 'using' keyword is to make sure the SHA256 object is disposed at the end of scope. + using SHA256 sha = SHA256.Create(); + + byte[] hash = sha.ComputeHash(Encoding.UTF8.GetBytes(fullTypeName)); + + return BitConverter.ToInt64(hash); } - public static string GetTypeName(System.Type type) + public static string GetTypeName(Type type) { return type.Name; } - + public static bool IsUserDefinedType() { throw new InvalidOperationException("This method can only be called in the Udon runtime"); } - + /// /// Checks if the type T is a user-defined type with an overridden Equals method. /// @@ -52,15 +58,15 @@ public static long GetTypeID() } // These may be extended in the future to handle the edge cases with type names - public static string GetTypeName(System.Type type) + public static string GetTypeName(Type type) { - return Internal.UdonSharpInternalUtility.GetTypeID(type); + return Internal.UdonSharpInternalUtility.GetTypeName(type); } - //public static string GetTypeNamespace(System.Type type) - //{ - // return type.Namespace; - //} + /*public static string GetTypeNamespace(Type type) + { + return type.Namespace; + }*/ // Placeholder stubs, won't give valid info unless used in the Udon runtime public static int GetUdonScriptVersion() @@ -68,9 +74,9 @@ public static int GetUdonScriptVersion() return 0; } - public static System.DateTime GetLastCompileDate() + public static DateTime GetLastCompileDate() { - return System.DateTime.Now; + return DateTime.Now; } public static string GetCompilerVersionString()