diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 8f19594e6d..50d7860f35 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -1658,6 +1658,9 @@ proc semDeref(c: PContext, n: PNode, flags: TExprFlags): PNode = n[0] = a result = n var t = skipTypes(n[0].typ, {tyGenericInst, tyVar, tyLent, tyAlias, tySink, tyOwned}) + if t.kind == tyTypeDesc: + localError(c.config, n.info, "missing generic parameter") + return nil case t.kind of tyRef, tyPtr: n.typ = t.elementType of tyMetaTypes, tyFromExpr: diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 613b1557d3..263ec13e74 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -2219,7 +2219,8 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType = else: result = semTypeNode(c, whenResult, prev) of nkBracketExpr: - checkMinSonsLen(n, 2, c.config) + # Actually len >= 2 is required, but it doesn't print errors nicely with empty brackets + checkMinSonsLen(n, 1, c.config) var head = n[0] var s = if head.kind notin nkCallKinds: semTypeIdent(c, head) else: symFromExpectedTypeNode(c, semExpr(c, head)) @@ -2237,10 +2238,21 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType = incl result, tfHasAsgn of mVarargs: result = semVarargs(c, n, prev) of mTypeDesc, mType, mTypeOf: - result = makeTypeDesc(c, semTypeNode(c, n[1], nil)) - result.incl tfExplicit + if n.len != 2: + let name = case s.magic: + of mTypeDesc: "typedesc" + of mType: "type" + of mTypeOf: "typeof" + else: "" + localError(c.config, n.info, errXExpectsOneTypeParam % name) + else: + result = makeTypeDesc(c, semTypeNode(c, n[1], nil)) + result.incl tfExplicit of mStatic: - result = semStaticType(c, n[1], prev) + if n.len != 2: + localError(c.config, n.info, errXExpectsOneTypeParam % "static") + else: + result = semStaticType(c, n[1], prev) of mExpr: result = semTypeNode(c, n[0], nil) if result != nil: @@ -2250,9 +2262,11 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType = for i in 1..