Skip to content

Commit

Permalink
_
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Feb 11, 2020
1 parent 79272a6 commit 6ba26f9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
12 changes: 8 additions & 4 deletions compiler/renderer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ when defined(nimHasUsed):

import
lexer, options, idents, strutils, ast, msgs, lineinfos
from compiler/renderer2 import nil
template renderTree2(a): untyped = renderer2.renderTree(a)

type
TRenderFlag* = enum
Expand Down Expand Up @@ -534,7 +536,7 @@ proc lsub(g: TSrcGen; n: PNode): int =
else: result = MaxLineLen + 1

proc fits(g: TSrcGen, x: int): bool =
result = g.indent + x <= MaxLineLen
result = x <= MaxLineLen

type
TSubFlag = enum
Expand Down Expand Up @@ -574,7 +576,8 @@ proc gcommaAux(g: var TSrcGen, n: PNode, ind: int, start: int = 0,
for i in start..n.len + theEnd:
var c = i < n.len + theEnd
var sublen = lsub(g, n[i]) + ord(c)
if not fits(g, sublen) and (ind + sublen < MaxLineLen): optNL(g, ind)
if not fits(g, g.lineLen + sublen):
optNL(g, ind)
let oldLen = g.tokens.len
gsub(g, n[i])
if c:
Expand Down Expand Up @@ -1141,11 +1144,12 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) =
putWithSpace(g, tkColon, ":")
gsub(g, n, 1)
of nkInfix:
let oldLineLen = g.lineLen # we cache this because lineLen gets updated below
infixArgument(g, n, 1)
put(g, tkSpaces, Space)
gsub(g, n, 0) # binary operator
# will overfit for larger operators than "+", eg "<="
if n.len == 3 and not fits(g, lsub(g, n[1]) + lsub(g, n[2]) + len(" + ")):
# eg: `n1 == n2` decompses as following sum:
if n.len == 3 and not fits(g, oldLineLen + lsub(g, n[1]) + lsub(g, n[2]) + lsub(g, n[0]) + len(" ")):
optNL(g, g.indent + longIndentWid)
else:
put(g, tkSpaces, Space)
Expand Down
4 changes: 3 additions & 1 deletion tests/errmsgs/tgcsafety.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ errormsg: "type mismatch: got <AsyncHttpServer, Port, proc (req: Request): Futur
nimout: '''
type mismatch: got <AsyncHttpServer, Port, proc (req: Request): Future[system.void]{.locks: <unknown>.}>
but expected one of:
proc serve(server: AsyncHttpServer; port: Port; callback: proc (request: Request): Future[void] {.closure, gcsafe.}; address = ""): owned(Future[void])
proc serve(server: AsyncHttpServer; port: Port;
callback: proc (request: Request): Future[void] {.closure, gcsafe.};
address = ""): owned(Future[void])
first type mismatch at position: 3
required type for callback: proc (request: Request): Future[system.void]{.closure, gcsafe.}
but expression 'cb' is of type: proc (req: Request): Future[system.void]{.locks: <unknown>.}
Expand Down
4 changes: 2 additions & 2 deletions tests/macros/tdumpast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ fun2()

macro fun3(): untyped =
let n = quote do:
int | array | seq | object | ptr | pointer | ref
doAssert n.repr == "int | array | seq | object | ptr | pointer | ref", n.repr
int | float | array | seq | object | ptr | pointer | float32
doAssert n.repr == "int | float | array | seq | object | ptr | pointer | float32", n.repr
fun3()

0 comments on commit 6ba26f9

Please sign in to comment.