From dacfea5475ef3b6bb44ed3369661e44a869475e0 Mon Sep 17 00:00:00 2001 From: Chris Wesseling Date: Tue, 14 Nov 2023 18:52:29 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20Make=20=3D=3D=3D=20and=20!=3D=3D?= =?UTF-8?q?=20=20a=20=E2=86=92=20a=20=E2=86=92=20bool?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit a → b → bool doesn't make sense, because when a and b are different types, `===` is a contradiction and `!==` a tautology. --- src/parser.ts | 4 ++-- test-d/tests.json | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/parser.ts b/src/parser.ts index fd01a1e..ed3cfd1 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -52,8 +52,8 @@ export const defaultContext = makeContext({ // forcing === and !== isn't a eslint rule for nothing... '==': forall([a, b], f(a, b, bool)), '!=': forall([a, b], f(a, b, bool)), - '===': forall([a, b], f(a, b, bool)), - '!==': forall([a, b], f(a, b, bool)), + '===': forall([a], f(a, a, bool)), + '!==': forall([a], f(a, a, bool)), '!': forall([a], f(a, bool)), '!!': forall([a], f(a, bool)), or: forall([a, b], f(a, b, bool)), diff --git a/test-d/tests.json b/test-d/tests.json index d115b59..af73d57 100644 --- a/test-d/tests.json +++ b/test-d/tests.json @@ -13,14 +13,14 @@ [ {"==":[1,"1"]}, {}, true ], [ {"==":[1,2]}, {}, false ], [ {"===":[1,1]}, {}, true ], - [ {"===":[1,"1"]}, {}, false ], + [ {"===":[1,"1"]}, {}, false, "Number and String" ], [ {"===":[1,2]}, {}, false ], [ {"!=":[1,2]}, {}, true ], [ {"!=":[1,1]}, {}, false ], [ {"!=":[1,"1"]}, {}, false ], [ {"!==":[1,2]}, {}, true ], [ {"!==":[1,1]}, {}, false ], - [ {"!==":[1,"1"]}, {}, true ], + [ {"!==":[1,"1"]}, {}, true, "Number and String" ], [ {">":[2,1]}, {}, true ], [ {">":[1,1]}, {}, false ], [ {">":[1,2]}, {}, false ], @@ -156,7 +156,7 @@ [{"if":[ "0", "apple", "banana"]}, null, "apple"], "You can cast a string to numeric with a unary + ", - [{"===":[0,"0"]}, null, false], + [{"===":[0,"0"]}, null, false, "Number and String" ], [{"===":[0,{"+":"0"}]}, null, true], [{"if":[ {"+":"0"}, "apple", "banana"]}, null, "banana"], [{"if":[ {"+":"1"}, "apple", "banana"]}, null, "apple"],