diff --git a/compiler/ast/ast_query.nim b/compiler/ast/ast_query.nim index 57533b37bbe..bfe706246ca 100644 --- a/compiler/ast/ast_query.nim +++ b/compiler/ast/ast_query.nim @@ -123,8 +123,6 @@ const nkIteratorTy, nkSharedTy, nkEnumTy, - nkStmtListType, - nkBlockType } # TODO: replace with `nk*Literals`, see above diff --git a/compiler/ast/ast_types.nim b/compiler/ast/ast_types.nim index b214870ab14..1f0730c04c0 100644 --- a/compiler/ast/ast_types.nim +++ b/compiler/ast/ast_types.nim @@ -201,9 +201,6 @@ type nkBlockExpr ## a statement block ending in an expr; this is used ## to allow powerful multi-line templates that open a ## temporary scope - nkStmtListType ## a statement list ending in a type; for macros - nkBlockType ## a statement block ending in a type; for macros - ## types as syntactic trees: nkWith ## distinct with `foo` nkWithout ## distinct without `foo` diff --git a/compiler/ast/renderer.nim b/compiler/ast/renderer.nim index d59a9dadd75..991c0113756 100644 --- a/compiler/ast/renderer.nim +++ b/compiler/ast/renderer.nim @@ -633,14 +633,14 @@ proc longMode(g: TSrcGen; n: PNode, start: int = 0, theEnd: int = - 1): bool = proc gstmts(g: var TSrcGen, n: PNode, c: TContext, doIndent=true) = if n.kind == nkEmpty: return - if n.kind in {nkStmtList, nkStmtListExpr, nkStmtListType}: + if n.kind in {nkStmtList, nkStmtListExpr}: if doIndent: indentNL(g) for i in 0.. 0: optNL(g, n[i-1], n[i]) else: optNL(g) - if n[i].kind in {nkStmtList, nkStmtListExpr, nkStmtListType}: + if n[i].kind in {nkStmtList, nkStmtListExpr}: gstmts(g, n[i], c, doIndent=false) else: gsub(g, n[i], fromStmtList = true) @@ -1421,7 +1421,7 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext, fromStmtList = false) = put(g, tkSpaces, Space) putWithSpace(g, tkEquals, "=") gsub(g, n, 1) - of nkStmtList, nkStmtListExpr, nkStmtListType: + of nkStmtList, nkStmtListExpr: if n.len == 1 and n[0].kind == nkDiscardStmt: put(g, tkParLe, "(") gsub(g, n[0]) @@ -1654,7 +1654,7 @@ proc renderTree*(n: PNode, renderFlags: TRenderFlags = {}): string = # do not indent the initial statement list so that # writeFile("file.nim", repr n) # produces working Nim code: - if n.kind in {nkStmtList, nkStmtListExpr, nkStmtListType}: + if n.kind in {nkStmtList, nkStmtListExpr}: gstmts(g, n, emptyContext, doIndent = false) else: gsub(g, n) diff --git a/compiler/front/condsyms.nim b/compiler/front/condsyms.nim index d50a5b440ed..c60e9a91f67 100644 --- a/compiler/front/condsyms.nim +++ b/compiler/front/condsyms.nim @@ -74,3 +74,4 @@ proc initDefines*(symbols: StringTableRef) = defineSymbol("nimskullReworkStaticExec") defineSymbol("nimskullNoMagicNewAssign") defineSymbol("nimskullNoFloat128") + defineSymbol("nimskullHasNkStmtListTypeAndNkBlockTypeRemoved") diff --git a/compiler/mir/mirgen.nim b/compiler/mir/mirgen.nim index 3a1666de2e4..530244dc165 100644 --- a/compiler/mir/mirgen.nim +++ b/compiler/mir/mirgen.nim @@ -551,24 +551,6 @@ proc genTypeExpr(c: var TCtx, n: PNode): Value = # FIXME: a ``nkStmtListExpr`` shouldn't reach here, but it does. See # ``tests/lang_callable/generics/t18859.nim`` for a case where it # does - if n[^1].typ.kind == tyTypeDesc: - genTypeExpr(c, n.lastSon) - else: - # HACK: this is big hack. Consider the following case: - # - # .. code-block:: nim - # - # type Obj[T] = object - # p: T not nil - # - # var x: Obj[ref int] - # - # The ``T not nil`` is a ``nkStmtListType`` node with a single - # ``nkInfix`` sub-node, where the latter doesn't use a - # ``tyTypeDesc`` type but a ``tyRef`` instead. For now, we work - # around this by using the type of the ``nkStmtListType`` - typeLit(n.typ) - of nkBlockType: genTypeExpr(c, n.lastSon) of nkSym: case n.sym.kind diff --git a/compiler/sem/semexprs.nim b/compiler/sem/semexprs.nim index dcafe9b8fcb..39ed98b095a 100644 --- a/compiler/sem/semexprs.nim +++ b/compiler/sem/semexprs.nim @@ -3623,9 +3623,6 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode = result = semTypeNode2(c, n, nil) # a type expression is of type ``typeDesc[T]`` result.typ = makeTypeDesc(c, result.typ.skipTypes({tyTypeDesc})) - of nkStmtListType: - result = semTypeNode2(c, n, nil) - result.typ = makeTypeDesc(c, result.typ) of nkCall, nkInfix, nkPrefix, nkPostfix, nkCommand, nkCallStrLit: # check if it is an expression macro: checkMinSonsLen(n, 1, c.config) diff --git a/compiler/sem/semfold.nim b/compiler/sem/semfold.nim index 84f4bfeb929..5079b2a5cfd 100644 --- a/compiler/sem/semfold.nim +++ b/compiler/sem/semfold.nim @@ -857,14 +857,14 @@ proc foldConstExprAux(m: PSym, n: PNode, idgen: IdGenerator, g: ModuleGraph): Fo return of nkSym: discard "may be folded away" - of nkTypeExprs - {nkStmtListType, nkBlockType}: + of nkTypeExprs: result.node = newNodeIT(nkType, n.info, n.typ) of nkBracket, nkCurly, nkTupleConstr, nkRange, nkAddr, nkHiddenAddr, nkHiddenDeref, nkDerefExpr, nkBracketExpr, nkCallKinds, nkIfExpr, nkElifExpr, nkElseExpr, nkElse, nkElifBranch: for it in n.items: result.add foldConstExprAux(m, it, idgen, g) - of nkCast, nkConv, nkHiddenStdConv, nkHiddenSubConv, nkBlockExpr, nkBlockType: + of nkCast, nkConv, nkHiddenStdConv, nkHiddenSubConv, nkBlockExpr: # the first slot only holds the type/label, which we don't need to traverse # into / fold result.add n[0] @@ -888,7 +888,7 @@ proc foldConstExprAux(m: PSym, n: PNode, idgen: IdGenerator, g: ModuleGraph): Fo result.add n[0] # skip the type slot for i in 1..