From 72ced1bda5849146e4d1bd4be963d6e2fed4b2cc Mon Sep 17 00:00:00 2001 From: Friedrich von Never Date: Tue, 21 Nov 2023 23:35:32 +0100 Subject: [PATCH] (#354) TODO sweep, better typoe checks --- Cesium.CodeGen/Extensions/TypeSystemEx.cs | 25 ++++++++++++++----- .../CSharpCompilationUtil.cs | 2 -- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Cesium.CodeGen/Extensions/TypeSystemEx.cs b/Cesium.CodeGen/Extensions/TypeSystemEx.cs index 2d076083..1ec35820 100644 --- a/Cesium.CodeGen/Extensions/TypeSystemEx.cs +++ b/Cesium.CodeGen/Extensions/TypeSystemEx.cs @@ -160,18 +160,31 @@ private static bool TypesCorrespond(TypeSystem typeSystem, TypeReference type1, return type1 is PointerType pt && pt.ElementType.IsEqualTo(typeSystem.Void); } - if (!type2.IsGenericInstance) return false; - type2 = type2.GetElementType(); + if (type2 is not GenericInstanceType type2Instance) return false; + var type2Definition = type2.GetElementType(); if (type1.IsPointer) { - // TODO: Analyze the generic argument. - return type2.FullName == CPtrFullTypeName; + if (type2Definition.FullName != CPtrFullTypeName) + { + // Non-pointer gets compared to a pointer. + return false; + } + + var pointed1 = ((PointerType)type1).ElementType; + var pointed2 = type2Instance.GenericArguments.Single(); + return TypesCorrespond(typeSystem, pointed1, pointed2); } if (type1.IsFunctionPointer) { - // TODO: Analyze the generic argument. - return type2.FullName == FuncPtrFullTypeName; + if (type2Definition.FullName != FuncPtrFullTypeName) + { + // A function pointer gets compared to not a function pointer. + return false; + } + + // TODO: Compare the function type signatures here. + return true; } throw new AssertException("Impossible: type1 should be either a pointer or a function pointer."); diff --git a/Cesium.Test.Framework/CSharpCompilationUtil.cs b/Cesium.Test.Framework/CSharpCompilationUtil.cs index 1dbf4bb7..255195f5 100644 --- a/Cesium.Test.Framework/CSharpCompilationUtil.cs +++ b/Cesium.Test.Framework/CSharpCompilationUtil.cs @@ -15,10 +15,8 @@ public static class CSharpCompilationUtil private const string _projectName = "TestProject"; /// Semaphore that controls the amount of simultaneously running tests. - // TODO: Should not be static, make a fixture. private static readonly SemaphoreSlim _testSemaphore = new(Environment.ProcessorCount); - // TODO: Support references public static async Task CompileCSharpAssembly( ITestOutputHelper output, TargetRuntimeDescriptor runtime,