shithub: mc

Download patch

ref: 2fad146c7146c1d522c1d20ed80663cc4701ea9a
parent: 7efe6165e6c644a51b50e91c897a9f19256db92d
author: Ori Bernstein <[email protected]>
date: Sun Jun 17 20:23:20 EDT 2012

Provide "default typing" for non-int numbers.

    Do I want to revisit this? Floating point may be something I
    want to avoid defaulting to if we're not sure things are ints.

    Perhaps have Tcfloat, and only default if that's been inferred?

--- a/parse/infer.c
+++ b/parse/infer.c
@@ -564,16 +564,21 @@
 static Type *tyfix(Node *ctx, Type *t)
 {
     static Type *tyint;
+    static Type *tyfloat;
     size_t i;
     char buf[1024];
 
     if (!tyint)
         tyint = mkty(-1, Tyint);
+    if (!tyfloat)
+        tyfloat = mkty(-1, Tyfloat64);
 
     t = tf(t);
     if (t->type == Tyvar) {
         if (hascstr(t, cstrtab[Tcint]) && cstrcheck(t, tyint))
             return tyint;
+        if (hascstr(t, cstrtab[Tcnum]) && cstrcheck(t, tyfloat))
+            return tyfloat;
     } else {
         if (t->type == Tyarray)
             typesub(t->asize);