diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2022-12-10 04:38:55 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-09 21:38:55 +0100 |
commit | db56fc3bcbc97772d6e7690f44157d1009b2a2a4 (patch) | |
tree | 96449a951643c8aba300ae23ead4edf897ff0056 | |
parent | da3274d1b3bb5cc737a5aca900dd231e4223fa60 (diff) | |
download | Nim-db56fc3bcbc97772d6e7690f44157d1009b2a2a4.tar.gz |
Revert "fix #15836 proc arg return type auto unexpectly match proc with concr…" (#21057)
Revert "fix #15836 proc arg return type auto unexpectly match proc with concr… (#21044)" This reverts commit 0cd9bdcf9f6802421e0d8e4c28fc732012af605e.
-rw-r--r-- | compiler/ast.nim | 3 | ||||
-rw-r--r-- | compiler/docgen.nim | 2 | ||||
-rw-r--r-- | compiler/lookups.nim | 2 | ||||
-rw-r--r-- | compiler/sem.nim | 4 | ||||
-rw-r--r-- | compiler/semexprs.nim | 4 | ||||
-rw-r--r-- | compiler/semstmts.nim | 3 | ||||
-rw-r--r-- | compiler/semtypes.nim | 4 | ||||
-rw-r--r-- | tests/proc/tillegalreturntype.nim | 2 | ||||
-rw-r--r-- | tests/types/t15836.nim | 11 |
9 files changed, 12 insertions, 23 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index 198d21bea..9679c10c1 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -2047,9 +2047,6 @@ template detailedInfo*(sym: PSym): string = proc isInlineIterator*(typ: PType): bool {.inline.} = typ.kind == tyProc and tfIterator in typ.flags and typ.callConv != ccClosure -proc isIterator*(typ: PType): bool {.inline.} = - typ.kind == tyProc and tfIterator in typ.flags - proc isClosureIterator*(typ: PType): bool {.inline.} = typ.kind == tyProc and tfIterator in typ.flags and typ.callConv == ccClosure diff --git a/compiler/docgen.nim b/compiler/docgen.nim index 0a24d2e09..e2c04430c 100644 --- a/compiler/docgen.nim +++ b/compiler/docgen.nim @@ -558,7 +558,7 @@ proc runAllExamples(d: PDoc) = proc quoted(a: string): string = result.addQuoted(a) -proc toInstantiationInfo(conf: ConfigRef, info: TLineInfo): (string, int, int) = +proc toInstantiationInfo(conf: ConfigRef, info: TLineInfo): auto = # xxx expose in compiler/lineinfos.nim (conf.toMsgFilename(info), info.line.int, info.col.int + ColOffset) diff --git a/compiler/lookups.nim b/compiler/lookups.nim index df5a5333e..2121982a6 100644 --- a/compiler/lookups.nim +++ b/compiler/lookups.nim @@ -422,7 +422,7 @@ type SpellCandidate = object msg: string sym: PSym -template toOrderTup(a: SpellCandidate): (int, int, string) = +template toOrderTup(a: SpellCandidate): auto = # `dist` is first, to favor nearby matches # `depth` is next, to favor nearby enclosing scopes among ties # `sym.name.s` is last, to make the list ordered and deterministic among ties diff --git a/compiler/sem.nim b/compiler/sem.nim index 1f8e217b3..a1388bd87 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -81,7 +81,7 @@ template semIdeForTemplateOrGeneric(c: PContext; n: PNode; proc fitNodePostMatch(c: PContext, formal: PType, arg: PNode): PNode = let x = arg.skipConv if (x.kind == nkCurly and formal.kind == tySet and formal.base.kind != tyGenericParam) or - (x.kind in {nkPar, nkTupleConstr}) and formal.kind notin {tyUntyped, tyBuiltInTypeClass, tyAnything}: + (x.kind in {nkPar, nkTupleConstr}) and formal.kind notin {tyUntyped, tyBuiltInTypeClass}: changeType(c, x, formal, check=true) result = arg result = skipHiddenSubConv(result, c.graph, c.idgen) @@ -439,7 +439,7 @@ proc semAfterMacroCall(c: PContext, call, macroResult: PNode, # does not mean we expect a tyTypeDesc. retType = retType[0] case retType.kind - of tyUntyped, tyAnything: + of tyUntyped: # Not expecting a type here allows templates like in ``tmodulealias.in``. result = semExpr(c, result, flags, expectedType) of tyTyped: diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index a467c408a..22a247ceb 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -1913,8 +1913,8 @@ proc semProcBody(c: PContext, n: PNode; expectedType: PType = nil): PNode = else: localError(c.config, c.p.resultSym.info, errCannotInferReturnType % c.p.owner.name.s) - if isIterator(c.p.owner.typ) and c.p.owner.typ[0] != nil and - c.p.owner.typ[0].kind == tyAnything: + if isInlineIterator(c.p.owner.typ) and c.p.owner.typ[0] != nil and + c.p.owner.typ[0].kind == tyUntyped: localError(c.config, c.p.owner.info, errCannotInferReturnType % c.p.owner.name.s) closeScope(c) diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index d19d75611..a006013b8 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -2179,7 +2179,8 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind, if hasProto: localError(c.config, n.info, errImplOfXexpected % proto.name.s) if {sfImportc, sfBorrow, sfError} * s.flags == {} and s.magic == mNone: # this is a forward declaration and we're building the prototype - if s.kind in {skProc, skFunc} and s.typ[0] != nil and s.typ[0].kind == tyAnything: + if s.kind in {skProc, skFunc} and s.typ[0] != nil and s.typ[0].kind == tyUntyped: + # `auto` is represented as `tyUntyped` at this point in compilation. localError(c.config, n[paramsPos][0].info, "return type 'auto' cannot be used in forward declarations") incl(s.flags, sfForward) diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index dca0d753b..3eaf29755 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -1405,7 +1405,9 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode, "' is only valid for macros and templates") # 'auto' as a return type does not imply a generic: elif r.kind == tyAnything: - discard + # 'p(): auto' and 'p(): untyped' are equivalent, but the rest of the + # compiler is hardly aware of 'auto': + r = newTypeS(tyUntyped, c) elif r.kind == tyStatic: # type allowed should forbid this type discard diff --git a/tests/proc/tillegalreturntype.nim b/tests/proc/tillegalreturntype.nim index 1076f7f75..799cad53a 100644 --- a/tests/proc/tillegalreturntype.nim +++ b/tests/proc/tillegalreturntype.nim @@ -1,5 +1,5 @@ discard """ - cmd: "nim check --hints:off $file" + cmd: "nim check $file" errormsg: "" nimout: ''' tillegalreturntype.nim(11, 11) Error: return type 'typed' is only valid for macros and templates diff --git a/tests/types/t15836.nim b/tests/types/t15836.nim deleted file mode 100644 index 9c0c26dec..000000000 --- a/tests/types/t15836.nim +++ /dev/null @@ -1,11 +0,0 @@ -discard """ - errormsg: "type mismatch: got <string> but expected 'int'" - line: 11 -""" - -proc takesProc[T](x: T, f: proc(x: T): int) = - echo f(x) + 2 - -takesProc(1, proc (a: int): int = 2) # ok, prints 4 -takesProc(1, proc (a: auto): auto = 2) # ok, prints 4 -takesProc(1, proc (a: auto): auto = "uh uh") # prints garbage |