From 25457ffa19b60849a44e3113841cb6dbef3d15e6 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Sun, 19 Jun 2022 21:33:20 +0000 Subject: [PATCH] don't try to type-guess on list expressions in case --- kiss/src/kiss/FieldForms.hx | 3 ++- kiss/src/kiss/Helpers.hx | 10 ++++++---- kiss/src/kiss/SpecialForms.hx | 35 +++++++++++++++++++++++------------ 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/kiss/src/kiss/FieldForms.hx b/kiss/src/kiss/FieldForms.hx index 2ed14717..bdbeb9db 100644 --- a/kiss/src/kiss/FieldForms.hx +++ b/kiss/src/kiss/FieldForms.hx @@ -102,7 +102,8 @@ class FieldForms { var access = fieldAccess(formName, name, args[0]); var type = Helpers.explicitType(args[0]); - k.typeHints.push({name: name, type: type}); + if (type != null) + k.typeHints.push({name: name, type: type}); ({ name: name, diff --git a/kiss/src/kiss/Helpers.hx b/kiss/src/kiss/Helpers.hx index dde00c67..f4952aff 100644 --- a/kiss/src/kiss/Helpers.hx +++ b/kiss/src/kiss/Helpers.hx @@ -173,7 +173,7 @@ class Helpers { }; } - var args = switch (argList.def) { + var args:Array = switch (argList.def) { case ListExp(funcArgs): funcArgs.map(makeFuncArg); case CallExp(_, _): @@ -190,7 +190,8 @@ class Helpers { }]; for (v in vars) { - k.typeHints.push(v); + if (v.type != null) + k.typeHints.push(v); } var expr = if (body.length == 0) { @@ -206,7 +207,8 @@ class Helpers { } for (v in vars) { - k.typeHints.remove(v); + if (v.type != null) + k.typeHints.remove(v); } // To make function args immutable by default, we would use (let...) instead of (begin...) @@ -217,7 +219,7 @@ class Helpers { ret: if (name != null) Helpers.explicitType(name) else null, args: args, expr: expr - } + }; } // The name of this function is confusing--it actually makes a Haxe `case` expression, not a switch-case expression diff --git a/kiss/src/kiss/SpecialForms.hx b/kiss/src/kiss/SpecialForms.hx index ed22dae3..14794598 100644 --- a/kiss/src/kiss/SpecialForms.hx +++ b/kiss/src/kiss/SpecialForms.hx @@ -204,7 +204,8 @@ class SpecialForms { } for (v in varDefs) { - k.typeHints.push(v); + if (v.type != null) + k.typeHints.push(v); } var block = EBlock([ @@ -213,7 +214,8 @@ class SpecialForms { ]).withMacroPosOf(wholeExp); for (v in varDefs) { - k.typeHints.remove(v); + if (v.type != null) + k.typeHints.remove(v); } block; @@ -322,16 +324,25 @@ class SpecialForms { // On C#, C++, and HashLink, value types (specifically Float and Int) cannot be null, so they cannot be compared with null. // Therefore a null case doesn't need to be added--and will cause a compile failure if it is. - var canCompareNull = if (Context.defined('cs') || Context.defined('cpp') || Context.defined('hl')) { - switch (exp.typeof(k.typeHints)) { - case Success(TAbstract(ref, [])) if (["Int", "Float", "Bool"].indexOf(ref.get().name) != -1): - false; - case Failure(_): - KissError.warnFromExp(args[0], "Can't detect whether expression can be null-checked"); - false; - default: true; - } - } else true; + var canCompareNull = switch (args[0].def) { + // don't try to type [multiple caseArgs]! It will never return! + case ListExp(_): + false; + default: + if (Context.defined('cs') || Context.defined('cpp') || Context.defined('hl')) { + var type = exp.typeof(k.typeHints); + switch (type) { + case null: + false; + case Success(TAbstract(ref, [])) if (["Int", "Float", "Bool"].indexOf(ref.get().name) != -1): + false; + case Failure(_): + KissError.warnFromExp(args[0], "Can't detect whether expression can be null-checked"); + false; + default: true; + } + } else true; + } var cases = args.slice(1); // case also override's haxe's switch() behavior by refusing to match null values against patterns.