Opened 11 years ago

Closed 10 years ago

Last modified 8 years ago

#60 closed defect (fixed)

Matching against literal strings is broken

Reported by: benl Owned by:
Priority: blocker Milestone:
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 (4)

comment:1 Changed 11 years ago by benl

Test is T60-StringMatch

comment:2 Changed 10 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.

comment:3 Changed 10 years ago by erikd

  • Resolution set to fixed
  • Status changed from new to closed

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.

comment:4 Changed 8 years ago by benl

  • Milestone 0.1.5 deleted

Milestone 0.1.5 deleted

Note: See TracTickets for help on using tickets.