better error message for 'proc' that is not intended to be used as a typeclass

This commit is contained in:
Andreas Rumpf 2018-12-15 09:09:46 +01:00
commit 446f911a17

View file

@ -1090,8 +1090,12 @@ proc typeSectionRightSidePass(c: PContext, n: PNode) =
proc checkForMetaFields(c: PContext; n: PNode) = proc checkForMetaFields(c: PContext; n: PNode) =
template checkMeta(t) = proc checkMeta(c: PContext; n: PNode; t: PType) =
if t != nil and t.isMetaType and tfGenericTypeParam notin t.flags: if t != nil and t.isMetaType and tfGenericTypeParam notin t.flags:
if t.kind == tyBuiltInTypeClass and t.len == 1 and t.sons[0].kind == tyProc:
localError(c.config, n.info, ("'$1' is not a concrete type; " &
"for a callback without parameters use 'proc()'") % t.typeToString)
else:
localError(c.config, n.info, errTIsNotAConcreteType % t.typeToString) localError(c.config, n.info, errTIsNotAConcreteType % t.typeToString)
if n.isNil: return if n.isNil: return
@ -1107,9 +1111,9 @@ proc checkForMetaFields(c: PContext; n: PNode) =
tyProc, tyGenericInvocation, tyGenericInst, tyAlias, tySink: tyProc, tyGenericInvocation, tyGenericInst, tyAlias, tySink:
let start = ord(t.kind in {tyGenericInvocation, tyGenericInst}) let start = ord(t.kind in {tyGenericInvocation, tyGenericInst})
for i in start ..< t.len: for i in start ..< t.len:
checkMeta(t.sons[i]) checkMeta(c, n, t.sons[i])
else: else:
checkMeta(t) checkMeta(c, n, t)
else: else:
internalAssert c.config, false internalAssert c.config, false