From d5ccef7d576f0ea952de352b5908a121bdff2f83 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Tue, 14 Jan 2020 15:28:32 -0800 Subject: [PATCH] fixup --- compiler/pathutils.nim | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/compiler/pathutils.nim b/compiler/pathutils.nim index 9ef43e3047e0..e3dd69628856 100644 --- a/compiler/pathutils.nim +++ b/compiler/pathutils.nim @@ -54,12 +54,19 @@ 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 @@ -67,7 +74,7 @@ when true: 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