added warning for confusing var declarations

This commit is contained in:
Araq 2012-07-26 08:47:54 +02:00
commit 2ff8d17369
5 changed files with 19 additions and 7 deletions

View file

@ -284,8 +284,8 @@ proc genSection(d: PDoc, kind: TSymKind) =
ord(kind).toRope, title, toRope(ord(kind) + 50), d.toc[kind]]) ord(kind).toRope, title, toRope(ord(kind) + 50), d.toc[kind]])
proc genOutFile(d: PDoc): PRope = proc genOutFile(d: PDoc): PRope =
var var
code, content: PRope = nil code, content: PRope
title = "" title = ""
var j = 0 var j = 0
var tmp = "" var tmp = ""

View file

@ -103,7 +103,7 @@ type
warnUnknownSubstitutionX, warnLanguageXNotSupported, warnCommentXIgnored, warnUnknownSubstitutionX, warnLanguageXNotSupported, warnCommentXIgnored,
warnXisPassedToProcVar, warnAnalysisLoophole, warnXisPassedToProcVar, warnAnalysisLoophole,
warnDifferentHeaps, warnWriteToForeignHeap, warnImplicitClosure, warnDifferentHeaps, warnWriteToForeignHeap, warnImplicitClosure,
warnUser, warnEachIdentIsTuple, warnUser,
hintSuccess, hintSuccessX, hintSuccess, hintSuccessX,
hintLineTooLong, hintXDeclaredButNotUsed, hintConvToBaseNotNeeded, hintLineTooLong, hintXDeclaredButNotUsed, hintConvToBaseNotNeeded,
hintConvFromXtoItselfNotNeeded, hintExprAlwaysX, hintQuitCalled, hintConvFromXtoItselfNotNeeded, hintExprAlwaysX, hintQuitCalled,
@ -346,6 +346,7 @@ const
warnDifferentHeaps: "possible inconsistency of thread local heaps [DifferentHeaps]", warnDifferentHeaps: "possible inconsistency of thread local heaps [DifferentHeaps]",
warnWriteToForeignHeap: "write to foreign heap [WriteToForeignHeap]", warnWriteToForeignHeap: "write to foreign heap [WriteToForeignHeap]",
warnImplicitClosure: "implicit closure convention: '$1' [ImplicitClosure]", warnImplicitClosure: "implicit closure convention: '$1' [ImplicitClosure]",
warnEachIdentIsTuple: "each identifier is a tuple [EachIdentIsTuple]",
warnUser: "$1 [User]", warnUser: "$1 [User]",
hintSuccess: "operation successful [Success]", hintSuccess: "operation successful [Success]",
hintSuccessX: "operation successful ($# lines compiled; $# sec total; $#) [SuccessX]", hintSuccessX: "operation successful ($# lines compiled; $# sec total; $#) [SuccessX]",
@ -363,14 +364,14 @@ const
hintUser: "$1 [User]"] hintUser: "$1 [User]"]
const const
WarningsToStr*: array[0..17, string] = ["CannotOpenFile", "OctalEscape", WarningsToStr*: array[0..18, string] = ["CannotOpenFile", "OctalEscape",
"XIsNeverRead", "XmightNotBeenInit", "XIsNeverRead", "XmightNotBeenInit",
"Deprecated", "ConfigDeprecated", "Deprecated", "ConfigDeprecated",
"SmallLshouldNotBeUsed", "UnknownMagic", "SmallLshouldNotBeUsed", "UnknownMagic",
"RedefinitionOfLabel", "UnknownSubstitutionX", "LanguageXNotSupported", "RedefinitionOfLabel", "UnknownSubstitutionX", "LanguageXNotSupported",
"CommentXIgnored", "XisPassedToProcVar", "CommentXIgnored", "XisPassedToProcVar",
"AnalysisLoophole", "DifferentHeaps", "WriteToForeignHeap", "AnalysisLoophole", "DifferentHeaps", "WriteToForeignHeap",
"ImplicitClosure,", "User"] "ImplicitClosure", "EachIdentIsTuple", "User"]
HintsToStr*: array[0..13, string] = ["Success", "SuccessX", "LineTooLong", HintsToStr*: array[0..13, string] = ["Success", "SuccessX", "LineTooLong",
"XDeclaredButNotUsed", "ConvToBaseNotNeeded", "ConvFromXtoItselfNotNeeded", "XDeclaredButNotUsed", "ConvToBaseNotNeeded", "ConvFromXtoItselfNotNeeded",

View file

@ -270,6 +270,9 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
b.sons[length-2] = a.sons[length-2] # keep type desc for doc generator b.sons[length-2] = a.sons[length-2] # keep type desc for doc generator
b.sons[length-1] = def b.sons[length-1] = def
addSon(result, b) addSon(result, b)
elif tup.kind == tyTuple and def.kind == nkPar and
a.kind == nkIdentDefs and a.len > 3:
Message(a.info, warnEachIdentIsTuple)
for j in countup(0, length-3): for j in countup(0, length-3):
var v = semIdentDef(c, a.sons[j], symkind) var v = semIdentDef(c, a.sons[j], symkind)
addInterfaceDecl(c, v) addInterfaceDecl(c, v)

View file

@ -244,7 +244,16 @@ proc transformConstSection(c: PTransf, v: PNode): PTransNode =
result[i] = PTransNode(b) result[i] = PTransNode(b)
else: else:
result[i] = PTransNode(it) result[i] = PTransNode(it)
proc trivialBody(s: PSym): PNode =
# a routine's body is trivially inlinable if marked as 'inline' and its
# body consists of only 1 statement. It is important that we perform this
# optimization here as 'distinct strings' may cause string copying otherwise:
# proc xml(s: string): TXmlString = return xmlstring(s)
# We have to generate a ``nkLineTracking`` node though to not lose
# debug information:
# XXX to implement
nil
proc hasContinue(n: PNode): bool = proc hasContinue(n: PNode): bool =
case n.kind case n.kind

View file

@ -4,7 +4,6 @@ version 0.9.0
- closure: implement closure support for procs capturing nested - closure: implement closure support for procs capturing nested
module vars module vars
- implicit deref for parameter matching - implicit deref for parameter matching
- deprecate ``var x, y = 0`` as it's confusing for tuple consistency
- ``borrow`` needs to take type classes into account - ``borrow`` needs to take type classes into account
- ``=`` should be overloadable; requires specialization for ``=`` - ``=`` should be overloadable; requires specialization for ``=``