haskell / haskell/c2hs

pseudo block c and enum, creates wrong line counting

Open
#262 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
211
Forks
52
PR merge metrics
No merged PRs in 30d

Description

WIth version 28.1 on Master branch following code will create wrong line counting:
```
#c
enum myEnum {
_A = 0,
_B = 1,
_C = 2
};
#endc
{#enum myEnum {underscoreToCase} deriving( Show, Eq) #}
```

Will create following code snippet
```
...
toEnum 2 = C
toEnum unmatched = error ("myEnum.toEnum: Cannot match " ++ show unmatched)

{-# LINE 8 "test.chs" #-}
...
```
This `LINE 8` should be `LINE 9`. This can be simply verified by repeating this the first code block. Each time, c2hs looses one line, eg.:
```
#c
enum myEnum {
_A = 0,
_B = 1,
_C = 2
};
#endc
{#enum myEnum {underscoreToCase} deriving( Show, Eq) #}

#c
enum myEnum2 {
_A2 = 0,
_B2 = 1,
_C2 = 2
};
#endc
{#enum myEnum2 {underscoreToCase} deriving( Show, Eq) #}
```
This leads to wrong line numbering in error/warnings.

Dumping the c2hs process gives following code for the pseudo-block of c:
```
#ce
#endc
#cn
#endc
#cu
#endc
#cm
#endc
#c
#endc
#cm
#endc
#cy
#endc
#cE
#endc
#cn
#endc
#cu
#endc
#cm
#endc
#c
#endc
#c{
#endc
#c

#endc
#c
#endc
#c
#endc
#c_
#endc
#cA
#endc
#c
#endc
#c=
#endc
#c
#endc
#c0
#endc
#c,
#endc
#c

...

#endc
#c}
#endc
#c;
#endc
#c

#endc
#c

#endc{#enum myEnum {underscoreToCase} deriving (Show, Eq) #}
```

I'm not sure, if this is how it should look like.
Any suggestions?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.