Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Jan 14, 2020
1 parent 2810654 commit d5ccef7
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions compiler/pathutils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,27 @@ when true:

proc `==`*[T: AnyPath](x, y: T): bool = eqImpl(x.string, y.string)

template checkValid(base: AbsoluteDir) =
# empty paths should not mean `cwd`
doAssert isAbsolute(base.string), base.string
template postProcessBase(base: AbsoluteDir): untyped =
# xxx: as argued here https://github.com/nim-lang/Nim/pull/10018#issuecomment-448192956
# empty paths should not mean `cwd` so the correct behavior would be to throw
# here and make sure `outDir` is always correctly initialized; for now
# we simply preserve pre-existing external semantics and treat it as `cwd`
when false:
doAssert isAbsolute(base.string), base.string
base
else:
if base.isEmpty: getCurrentDir().AbsoluteDir else: base

proc `/`*(base: AbsoluteDir; f: RelativeFile): AbsoluteFile =
checkValid(base)
let base = postProcessBase(base)
assert(not isAbsolute(f.string))
result = AbsoluteFile newStringOfCap(base.string.len + f.string.len)
var state = 0
addNormalizePath(base.string, result.string, state)
addNormalizePath(f.string, result.string, state)

proc `/`*(base: AbsoluteDir; f: RelativeDir): AbsoluteDir =
checkValid(base)
let base = postProcessBase(base)
assert(not isAbsolute(f.string))
result = AbsoluteDir newStringOfCap(base.string.len + f.string.len)
var state = 0
Expand Down

0 comments on commit d5ccef7

Please sign in to comment.