summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorJason Beetham <beefers331@gmail.com>2021-11-02 02:02:53 -0600
committerGitHub <noreply@github.com>2021-11-02 09:02:53 +0100
commitcc984217a98438de5a36447ea6574eb2c5da4ae4 (patch)
tree74a555d6260704d0cfb40c204204a61b47663f76 /compiler
parent24a75842998709b29ef50ef4cc10d30304efe3aa (diff)
downloadNim-cc984217a98438de5a36447ea6574eb2c5da4ae4.tar.gz
Fix VM's sametype impl to work for generics/typedescs (#19073)
* Fix vm's sametype implementation to properly handle generics and typedescs

* actually fixed sametype + have test

* added comments and removed unsafe code
Diffstat (limited to 'compiler')
-rw-r--r--compiler/types.nim5
-rw-r--r--compiler/vm.nim3
2 files changed, 7 insertions, 1 deletions
diff --git a/compiler/types.nim b/compiler/types.nim
index 2c7b91d9f..7cf02c240 100644
--- a/compiler/types.nim
+++ b/compiler/types.nim
@@ -1128,6 +1128,11 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
       a = a.skipTypes({tyDistinct, tyGenericInst})
       if a.kind != b.kind: return false
 
+  #[
+    The following code should not run in the case either side is an generic alias,
+    but it's not presently possible to distinguish the genericinsts from aliases of
+    objects ie `type A[T] = SomeObject`
+  ]#
   # this is required by tunique_type but makes no sense really:
   if tyDistinct notin {x.kind, y.kind} and x.kind == tyGenericInst and IgnoreTupleFields notin c.flags:
     let
diff --git a/compiler/vm.nim b/compiler/vm.nim
index 1b443aff1..b64545081 100644
--- a/compiler/vm.nim
+++ b/compiler/vm.nim
@@ -1044,7 +1044,8 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
                                      strictSymEquality=true))
     of opcSameNodeType:
       decodeBC(rkInt)
-      regs[ra].intVal = ord(regs[rb].node.typ.sameTypeOrNil regs[rc].node.typ)
+      regs[ra].intVal = ord(regs[rb].node.typ.sameTypeOrNil(regs[rc].node.typ, {ExactTypeDescValues, ExactGenericParams}))
+      # The types should exactly match which is why we pass `{ExactTypeDescValues..ExactGcSafety}`.
     of opcXor:
       decodeBC(rkInt)
       regs[ra].intVal = ord(regs[rb].intVal != regs[rc].intVal)