Noeud « Next »: , Noeud « Previous »: T4 Goals, Noeud « Up »: T4



4.6.2 T4 Samples

Type checking is optional, invoked by --types-check or -T:

     1 + "2"
     File 45: int-plus-string.tig
     $ tc int-plus-string.tig
     Example 46: tc int-plus-string.tig
     $ tc int-plus-string.tig --types-check
     error-->int-plus-string.tig:1.0-6: type mismatch
     error-->  right operand type: string
     error-->  expected type: int
     =>4
     Example 47: tc int-plus-string.tig --types-check

When there are several type errors, it is admitted that some remain hidden by others.

     unknown_function (unknown_variable)
     File 48: unknowns.tig
     $ tc unknowns.tig --types-check
     error-->unknowns.tig:1.0-34: unknown function: unknown_function
     =>4
     Example 49: tc unknowns.tig --types-check

Be sure to check the type of all the constructs.

     if 1 then 2
     File 50: bad-if.tig
     $ tc bad-if.tig --types-check
     error-->bad-if.tig:1.0-10: type mismatch
     error-->  then clause type: int
     error-->  else clause type: void
     =>4
     Example 51: tc bad-if.tig --types-check

Be aware that type and function declarations are recursive by chunks. For instance:

     let type one = { hd : int, tail : two }
         type two = { hd : int, tail : one }
         function one (hd : int, tail : two) : one
            = one { hd = hd, tail = tail }
         function two (hd : int, tail : one) : two
            = two { hd = hd, tail = tail }
         var one := one (11, two (22, nil))
     in
       print_int (one.tail.hd); print ("\n")
     end
     File 52: mutuals.tig
     $ tc mutuals.tig --types-check
     Example 53: tc mutuals.tig --types-check

In case you are interested, the result is:

     $ tc -H mutuals.tig >mutuals.hir
     Example 54: tc -H mutuals.tig >mutuals.hir
     $ havm mutuals.hir
     22
     Example 55: havm mutuals.hir