From 0f83738c2ec4395bb632e61861281bfaeea87ad0 Mon Sep 17 00:00:00 2001 From: Alex Snezhko Date: Sat, 2 Mar 2024 23:03:30 +0000 Subject: [PATCH] fix(stdlib): Fix `relativeTo` base comparison when arg 1: abs and arg 2: rel --- compiler/test/stdlib/path.test.gr | 5 +++++ stdlib/path.gr | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/test/stdlib/path.test.gr b/compiler/test/stdlib/path.test.gr index fed41b1f4..99ae14769 100644 --- a/compiler/test/stdlib/path.test.gr +++ b/compiler/test/stdlib/path.test.gr @@ -253,6 +253,11 @@ let relativeToTests = [ dest: "./a.txt", result: Err(Path.Incompatible(Path.DifferentBases)), }, + { + source: "./a.txt", + dest: "/bin", + result: Err(Path.Incompatible(Path.DifferentBases)), + }, ] List.forEach(({ source, dest, result }) => { diff --git a/stdlib/path.gr b/stdlib/path.gr index fa9e506c0..e106f5d4b 100644 --- a/stdlib/path.gr +++ b/stdlib/path.gr @@ -571,7 +571,7 @@ provide let relativeTo = (source, dest) => { let pathInfo2 = pathInfo(dest) let (base2, _, _) = pathInfo2 match ((base1, base2)) { - (Abs(_), Rel(_)) | (Abs(_), Rel(_)) => Err(Incompatible(DifferentBases)), + (Abs(_), Rel(_)) | (Rel(_), Abs(_)) => Err(Incompatible(DifferentBases)), _ => Result.map(toPath, relativeToHelper(pathInfo1, pathInfo2)), } }