Ticket #60 (closed defect: fixed)

Opened 6 years ago

Last modified 5 years ago

Matching against literal strings is broken

Reported by: benl Owned by:
Priority: blocker Milestone: 0.1.5
Component: Source Desugarer Version: 0.1.2
Keywords: Cc:

Description

With source

foo x
 = case x of
	"hello" 	-> 5
	"goodbye"	-> 47

main () 
	= putStr $ show $ foo "hello"

We get:

./test/Broken-skip/T60-StringMatch/Main.ddc.c: In function ‘Main_foo’:
./test/Broken-skip/T60-StringMatch/Main.ddc.c:27: error: switch quantity not an integer
./test/Broken-skip/T60-StringMatch/Main.ddc.c:28: error: case label does not reduce to an integer constant
./test/Broken-skip/T60-StringMatch/Main.ddc.c:41: error: switch quantity not an integer
./test/Broken-skip/T60-StringMatch/Main.ddc.c:42: error: case label does not reduce to an integer constant

Change History

Changed 6 years ago by benl

Test is T60-StringMatch

Changed 5 years ago by erikd

At some time after this bug was filed, it actually ended up compiling, but the executable now segfaults on code that looks like:

    _S(1)       = _force(_S(0));
    _vxTES0     = _unboxDirect(String, _S(1));
    if ((strcmp (_vxTES0, "hello") != 0)) {
        goto _dEF2_a1;
    }

However, the _unboxDirect macro looks like:

#define _unboxDirect(Type,data) \
	*((Type*) ((DataRS*)data)->payload)

and _S(1) when dumped with the new runtime debug function objDump looks like:

Obj 0xb75070dc (12 bytes)   tag 0x0
    id    : 0x21 (Data)
    arity : 1
  Obj 0xb75070bc (24 bytes)   tag 0x0
      id      : 0x31 (DataR)
      size    : 24
      payload : 06 00 00 00 05 00 00 00 68 65 6c 6c 6f 00 00 00 
              : "........hello..."

The problem here is that _unboxDirect expects a DataRS object, but is given a Data object.

Changed 5 years ago by erikd

  • status changed from new to closed
  • resolution set to fixed

Fixed in this commit.

Thu Aug 27 10:58:40 EST 2009 Richard Smith <richard-ddc@…>

  • #60 Desugar bindings against boxed literals into calls of Class.Eq.(==).

Closing.

Note: See TracTickets for help on using tickets.