# # # The Nim Compiler # (c) Copyright 2020 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. # ## This module contains 'typeAllowed' and friends which check ## for invalid types like `openArray[var int]`. import ast, renderer, options, semdata, types import std/intsets when defined(nimPreviewSlimSystem): import std/assertions type TTypeAllowedFlag* = enum taTupField, # field of a tuple taObjField, # field of an object taHeap, taConcept, taIsOpenArray, taNoUntyped taIsTemplateOrMacro taProcContextIsNotMacro taIsCastable taIsDefaultField taVoid # only allow direct void fields of objects/tuples TTypeAllowedFlags* = set[TTypeAllowedFlag] proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind; c: PContext; flags: TTypeAllowedFlags = {}): PType proc typeAllowedNode(marker: var IntSet, n: PNode, kind: TSymKind, c: PContext; flags: TTypeAllowedFlags = {}): PType = if n != nil: result = typeAllowedAux(marker, n.typ, kind, c, flags) if result == nil: case n.kind of nkNone..nkNilLit: discard else: #if n.kind == nkRecCase and kind in {skProc, skFunc, skConst}: # return n[0].typ for i in 0..