From 40fc2d0e768461517db4596907d3330b72d81600 Mon Sep 17 00:00:00 2001 From: metagn Date: Sat, 26 Oct 2024 18:49:02 +0300 Subject: [PATCH] include static types in type bound ops (#24366) refs https://github.com/nim-lang/Nim/pull/24315#discussion_r1816332587 --- compiler/types.nim | 3 +-- tests/sandwich/mstatic.nim | 8 ++++++++ tests/sandwich/tstatic.nim | 5 +++++ 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 tests/sandwich/mstatic.nim create mode 100644 tests/sandwich/tstatic.nim diff --git a/compiler/types.nim b/compiler/types.nim index 8ac3ff52f791..a6694ab26ac2 100644 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -1993,8 +1993,7 @@ proc nominalRoot*(t: PType): PType = #result = nominalRoot(t.skipModifier) result = nil of tyStatic: - # ? - result = nil + result = nominalRoot(t.base) else: # skips all typeclasses # is this correct for `concept`? diff --git a/tests/sandwich/mstatic.nim b/tests/sandwich/mstatic.nim new file mode 100644 index 000000000000..b07d339d5be9 --- /dev/null +++ b/tests/sandwich/mstatic.nim @@ -0,0 +1,8 @@ +type Foo* = object + x*, y*: int + +proc `$`*(x: static Foo): string = + "static Foo(" & $x.x & ", " & $x.y & ")" + +proc `$`*(x: Foo): string = + "runtime Foo(" & $x.x & ", " & $x.y & ")" diff --git a/tests/sandwich/tstatic.nim b/tests/sandwich/tstatic.nim new file mode 100644 index 000000000000..82ae607fc2dc --- /dev/null +++ b/tests/sandwich/tstatic.nim @@ -0,0 +1,5 @@ +from mstatic import Foo + +doAssert $Foo(x: 1, y: 2) == "static Foo(1, 2)" +let foo = Foo(x: 3, y: 4) +doAssert $foo == "runtime Foo(3, 4)"