File: 026_equal.sml

package info (click to toggle)
smlsharp 4.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 123,732 kB
  • sloc: ansic: 16,725; sh: 4,347; makefile: 2,191; java: 742; haskell: 493; ruby: 305; cpp: 284; pascal: 256; ml: 255; lisp: 141; asm: 97; sql: 74
file content (34 lines) | stat: -rw-r--r-- 1,121 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
infix =
(*val puts = _import "puts" : string -> int*)
val puts = SMLSharp_Builtin.General.ignore
fun f x = (x,x)
val t = (5,5)
val _ = if f 5 = t then puts "true" else (puts "false"; raise Fail "ng")

(*
2011-08-17 katsu

This code is expected to print "true" but actually it prints "false".

This wrong behaviour is due to the following reasons:
(1) Function "f" in line 2 is a polymorphic function, so compiler produces
    the code allocating an object of RECORD obj_type and dynamically
    computing its bitmap.
(2) In line 3, in contrast, compiler can compute the bitmap of "(5,5)"
    statically and it is 0, compiler generates the code allocating an
    UNBOXED_VECTOR object.
(3) In line 4, sml_obj_equal function is called to perform equality check.
    The sml_obj_equal first checks whether two objects have same obj_type.
    In this situation, since one is RECORD but another is UNBOXED_VECTOR,
    this check fails and then sml_obj_equal returns false.

This bug is occurred in not only the smlsharp_ng version but also the main
trunk version.

*)

(*
2011-08-17 katsu

Fixed by changeset e9a9524b0a3e.
*)