diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 2aa646dd60d91..30f4aa6ad0dbe 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -1361,7 +1361,8 @@ const tyDotOpTransparent = {tyVar, tyLent, tyPtr, tyRef, tyOwned, tyAlias, tySink} proc readTypeParameter(c: PContext, typ: PType, - paramName: PIdent, info: TLineInfo): PNode = + paramName: PIdent, info: TLineInfo, skip = true): PNode = + ## - **skip**: Skips generic aliases and tries to get the parameter from the aliased type. # Note: This function will return emptyNode when attempting to read # a static type parameter that is not yet resolved (e.g. this may # happen in proc signatures such as `proc(x: T): array[T.sizeParam, U]` @@ -1387,8 +1388,12 @@ proc readTypeParameter(c: PContext, typ: PType, discard if typ.kind != tyUserTypeClass: - let ty = if typ.kind == tyCompositeTypeClass: typ.firstGenericParam.skipGenericAlias - else: typ.skipGenericAlias + let ty = block: + let ty = if typ.kind == tyCompositeTypeClass: typ.firstGenericParam + else: typ + if skip: typ.skipGenericAlias() + else: typ + let tbody = ty[0] for s in 0.. 0: result = semGenericStmt(c, n) diff --git a/tests/generics/t24791.nim b/tests/generics/t24791.nim new file mode 100644 index 0000000000000..570308dcc778f --- /dev/null +++ b/tests/generics/t24791.nim @@ -0,0 +1,14 @@ +import std/options + +type + Foo[D: static int; T] = T + Bar[D] = Option[D] + Bizz = Foo[1, string] + Buzz = Foo[2, Option[string]] + + CheckPriority[T: static int; D] = Option[D] + +assert Bar[string].D is string +assert Bizz.D == 1 +assert Buzz.D == 2 +assert CheckPriority[3, string].T is string