From fb80f7707db7ef1c2138230eb74a816aac97d2db Mon Sep 17 00:00:00 2001 From: Tomohiro Date: Tue, 24 Feb 2026 17:39:06 +0900 Subject: [PATCH] fixes #16754 (#25519) This PR allows passing the defining type to generic types in the right side in a type definition like this: ```nim type Foo = object x: Option[Foo] ``` I think generic types should be instanciated after all given arguments are semchecked, because generic types can access information about them. (for example, `Option[T]` in std/option checks if `T` is a pointer like type) But in this case, need to instanciate `Option[Foo]` before type of `Foo.x` is determined. --- compiler/astdef.nim | 6 ++++- compiler/semtypes.nim | 26 ++++++++++++++++++- tests/generics/tself_type.nim | 48 +++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 tests/generics/tself_type.nim diff --git a/compiler/astdef.nim b/compiler/astdef.nim index b9a8aab3e1..242cdf3ef6 100644 --- a/compiler/astdef.nim +++ b/compiler/astdef.nim @@ -202,7 +202,11 @@ type tySequence, tyProc, tyPointer, tyOpenArray, - tyString, tyCstring, tyForward, + tyString, tyCstring, + tyForward, + # a type not yet semchecked + # When semcheck a type section, all types defined in it are initialized to tyForward + tyInt, tyInt8, tyInt16, tyInt32, tyInt64, # signed integers tyFloat, tyFloat32, tyFloat64, tyFloat128, tyUInt, tyUInt8, tyUInt16, tyUInt32, tyUInt64, diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 1a4bd24965..94435886a9 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -1739,6 +1739,7 @@ proc semGeneric(c: PContext, n: PNode, s: PSym, prev: PType): PType = var isConcrete = true let rType = m.call[0].typ let mIndex = if rType != nil: rType.len - 1 else: -1 + var hasForwardTypeParam = false for i in 1..