diff --git a/compiler/msgs.nim b/compiler/msgs.nim index 7f4f81dd07..17b2c46063 100644 --- a/compiler/msgs.nim +++ b/compiler/msgs.nim @@ -672,7 +672,7 @@ proc toFileLine*(info: TLineInfo): string {.inline.} = proc toFileLineCol*(info: TLineInfo): string {.inline.} = result = info.toFilename & "(" & $info.line & "," & $info.col & ")" -template `$`*(info: TLineInfo): expr = toFileLineCol(info) +proc `$`*(info: TLineInfo): string = toFileLineCol(info) proc `??`* (info: TLineInfo, filename: string): bool = # only for debugging purposes diff --git a/compiler/semcall.nim b/compiler/semcall.nim index a712cc195e..23362151bc 100644 --- a/compiler/semcall.nim +++ b/compiler/semcall.nim @@ -72,6 +72,9 @@ proc pickBestCandidate(c: PContext, headSymbol: PNode, if cmp < 0: best = z # x is better than the best so far elif cmp == 0: alt = z # x is as good as the best so far else: discard + #if sym.name.s == "shl" and (n.info ?? "net.nim"): + # echo "Matches ", n.info, " ", typeToString(sym.typ) + # writeMatches(z) sym = nextOverloadIter(o, c, headSymbol) proc notFoundError*(c: PContext, n: PNode, errors: CandidateErrors) = diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 647b147924..3c6cd248ea 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -205,10 +205,11 @@ proc cmpCandidates*(a, b: TCandidate): int = proc writeMatches*(c: TCandidate) = writeln(stdout, "exact matches: " & $c.exactMatches) - writeln(stdout, "subtype matches: " & $c.subtypeMatches) - writeln(stdout, "conv matches: " & $c.convMatches) - writeln(stdout, "intconv matches: " & $c.intConvMatches) writeln(stdout, "generic matches: " & $c.genericMatches) + writeln(stdout, "subtype matches: " & $c.subtypeMatches) + writeln(stdout, "intconv matches: " & $c.intConvMatches) + writeln(stdout, "conv matches: " & $c.convMatches) + writeln(stdout, "inheritance: " & $c.inheritancePenalty) proc argTypeToString(arg: PNode; prefer: TPreferedDesc): string = if arg.kind in nkSymChoices: @@ -267,7 +268,7 @@ proc concreteType(c: TCandidate, t: PType): PType = else: result = t # Note: empty is valid here -proc handleRange(f, a: PType, validconv: set[TTypeKind]): TTypeRelation = +proc handleRange(f, a: PType, min, max: TTypeKind): TTypeRelation = if a.kind == f.kind: result = isEqual else: @@ -281,9 +282,9 @@ proc handleRange(f, a: PType, validconv: set[TTypeKind]): TTypeRelation = # integer literal in the proper range; we want ``i16 + 4`` to stay an # ``int16`` operation so we declare the ``4`` pseudo-equal to int16 result = isFromIntLit - elif f.kind == tyInt and k in {tyInt8..tyInt32, tyUint8..tyUInt16}: + elif f.kind == tyInt and k in {tyInt8..tyInt32}: result = isIntConv - elif k in validconv: + elif k >= min and k <= max: result = isConvertible elif a.kind == tyRange and a.sons[0].kind in {tyInt..tyInt64, tyUInt8..tyUInt32} and @@ -663,16 +664,16 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation = result = isIntConv elif isConvertibleToRange(skipTypes(f, {tyRange}), a): result = isConvertible # a convertible to f - of tyInt: result = handleRange(f, a, {tyInt8..tyInt32,tyUInt8..tyUInt16}) - of tyInt8: result = handleRange(f, a, {tyInt8}) - of tyInt16: result = handleRange(f, a, {tyInt8..tyInt16,tyUInt8}) - of tyInt32: result = handleRange(f, a, {tyInt8..tyInt32,tyUInt8..tyUInt16}) - of tyInt64: result = handleRange(f, a, {tyInt..tyInt64,tyUInt8..tyUInt32}) - of tyUInt: result = handleRange(f, a, {tyUInt8..tyUInt32}) - of tyUInt8: result = handleRange(f, a, {tyUInt8}) - of tyUInt16: result = handleRange(f, a, {tyUInt8..tyUInt16}) - of tyUInt32: result = handleRange(f, a, {tyUInt8..tyUInt32}) - of tyUInt64: result = handleRange(f, a, {tyUInt..tyUInt64}) + of tyInt: result = handleRange(f, a, tyInt8, tyInt32) + of tyInt8: result = handleRange(f, a, tyInt8, tyInt8) + of tyInt16: result = handleRange(f, a, tyInt8, tyInt16) + of tyInt32: result = handleRange(f, a, tyInt8, tyInt32) + of tyInt64: result = handleRange(f, a, tyInt, tyInt64) + of tyUInt: result = handleRange(f, a, tyUInt8, tyUInt32) + of tyUInt8: result = handleRange(f, a, tyUInt8, tyUInt8) + of tyUInt16: result = handleRange(f, a, tyUInt8, tyUInt16) + of tyUInt32: result = handleRange(f, a, tyUInt8, tyUInt32) + of tyUInt64: result = handleRange(f, a, tyUInt, tyUInt64) of tyFloat: result = handleFloatRange(f, a) of tyFloat32: result = handleFloatRange(f, a) of tyFloat64: result = handleFloatRange(f, a) diff --git a/lib/pure/net.nim b/lib/pure/net.nim index 5e6bdae26e..4eacfea784 100644 --- a/lib/pure/net.nim +++ b/lib/pure/net.nim @@ -1036,7 +1036,7 @@ proc `$`*(address: TIpAddress): string = else: # Print address var printedLastGroup = false for i in 0..7: - var word:uint16 = (cast[uint16](address.address_v6[i*2])) shl 8u16 + var word:uint16 = (cast[uint16](address.address_v6[i*2])) shl 8 word = word or cast[uint16](address.address_v6[i*2+1]) if biggestZeroCount != 0 and # Check if group is in skip group @@ -1058,7 +1058,7 @@ proc `$`*(address: TIpAddress): string = else: # val >= 0xA result.add(chr(uint16(ord('a'))+val-0xA)) afterLeadingZeros = true - mask = mask shr 4u16 + mask = mask shr 4 printedLastGroup = true proc parseIPv4Address(address_str: string): TIpAddress = @@ -1073,7 +1073,7 @@ proc parseIPv4Address(address_str: string): TIpAddress = for i in 0 .. high(address_str): if address_str[i] in strutils.Digits: # Character is a number - currentByte = currentByte * 10u16 + + currentByte = currentByte * 10 + cast[uint16](ord(address_str[i]) - ord('0')) if currentByte > 255'u16: raise newException(ValueError, diff --git a/lib/pure/streams.nim b/lib/pure/streams.nim index 31aa7497de..55351ffd44 100644 --- a/lib/pure/streams.nim +++ b/lib/pure/streams.nim @@ -284,7 +284,7 @@ when not defined(js): proc newFileStream*(filename: string, mode: FileMode): FileStream = ## creates a new stream from the file named `filename` with the mode `mode`. ## If the file cannot be opened, nil is returned. See the `system - ## `_ module for a list of available TFileMode enums. + ## `_ module for a list of available FileMode enums. var f: File if open(f, filename, mode): result = newFileStream(f) diff --git a/tests/misc/tunsignedconv.nim b/tests/misc/tunsignedconv.nim index 547bc92ca1..a5453b4b88 100644 --- a/tests/misc/tunsignedconv.nim +++ b/tests/misc/tunsignedconv.nim @@ -1,6 +1,3 @@ -discard """ - output: '''''' -""" import unsigned diff --git a/todo.txt b/todo.txt index 0209012b40..04994d5caf 100644 --- a/todo.txt +++ b/todo.txt @@ -1,6 +1,8 @@ version 0.10 ============ +- document the 'finished' gotcha +- improve the docs for inheritance - The bitwise 'not' operator will be renamed to 'bnot' to prevent 'not 4 == 5' from compiling. -> requires 'mixin' annotation for procs! - parameter lists without type end up in 'experimental' @@ -11,7 +13,8 @@ version 0.10 - make nimble part of the distribution - split idetools into separate tool - split docgen into separate tool - +- special rule for ``[]=``, items, pairs +- BUG: echo with template `$`*(info: TLineInfo): expr = toFileLineCol(info) Concurrency @@ -32,7 +35,6 @@ Misc - make '--implicitStatic:on' the default - make tuple unpacking work in a non-var/let context -- special rule for ``[]=``, items, pairs - built-in 'getImpl' - prevent 'alloc(TypeWithGCedMemory)' - some table related tests are wrong (memory usage checks)