Wiki

Ticket #379 (new defect)

Opened 3 years ago

Last modified 3 years ago

enum of int8/uint8: translation wrong

Reported by: thriwkin Owned by:
Priority: critical Milestone:
Component: Cobra Compiler Version: 0.9.6
Keywords: enum Cc:

Description

If an enum is declared with an underlying type of int8 or uint8
then the translation to C# is incorrect:

  • int8 is translated to byte instead of sbyte
    -- without any message!
  • uint8 is translated to ubyte instead of byte,
    and the C# compiler gives this message:

"error: CS1008: Type byte, sbyte, short, ushort, int, uint, long, or ulong expected".

This program should compile and run:

enum EnumOfInt8
    of int8
    A, B, C

enum EnumOfUInt8
    of uint8
    A, B, C

class Program
    def main is shared
        t = Enum.getUnderlyingType(EnumOfInt8.getType)
        print t
        assert t is int8
        assert t is System.SByte
        t = Enum.getUnderlyingType(EnumOfUInt8.getType)
        print t
        assert t is uint8
        assert t is System.Byte

That of int8 is quietly translated incorrectly can cause a lot of trouble, especially in a large program.

Attachments

EnumDecl-writeSharpDef.patch Download (1.2 KB) - added by thriwkin 3 years ago.

Change History

Changed 3 years ago by thriwkin

Changed 3 years ago by thriwkin

I applied the attached .patch file to my working copy of Cobra svn:3116
-- now the above program compiles and runs.

Changed 3 years ago by hopscc

Looks like a good patch/fix but
With the patch applied does all the test suite also continue to run the same as
without the patch applied ?

(i.e Its not clear if you tested the patch on all the test code base - apologies if you did .
It is of course necessary that a patch fixes the problem but it also has to not cause any additional (new) failures (:-).

For particular paranoia heres the sequence

-1) rebuild the compiler with patch
0) test that the patched compiler fixes problem code/program
1) test run that Test suite passes with patched compiler - same output as an unpatched compiler
2) rebuild the cobra library
3) rerun test suite - passes with patched compiler and rebuilt cobra runtime lib
4) build a new compiler using the patched compiler
5) test that that compiler also passes all the test suite same as an unpatched compiler.

(step 4 and 5 test that the patch doesnt introduce a build perturbance into the compiler code that causes the tests to fail - one level of indirection)

now put the test program showing the error into the test suite so that both the error and fix is locked down....

Changed 3 years ago by thriwkin

With the patch applied
does all the test suite also continue to run the same as without the patch applied ?

Yes!
(And Yes for: #380, #378, #371, #372.
-- I allways do the regression testing before posting how to fix something.)



For particular paranoia heres the sequence ...

I think, that is not paranoia, it is just logical and necessary.


I do this testing a little bit different.
Can you please check if this is ok as well?

Whenever I want to know whether a modification of the compiler source does cause new failures,
I run a .bat file (on Windows), testAll.bat, which performs these steps:

testAll.bat: description

Names:
    c# : cobra.exe version 0.0.3116.#
    r# : Cobra.Core.dll version 0.0.3116.#
Steps:
    1. create NewSnapshot dir
    2. with c1 build c2 (in dir NewSnapshot)
    3. with c2 build c3 (in dir Source)
    4. with c3 build r3 (in dir Source)
    5. install r3 in GAC
    6. run tests (with c3 and r3 in GAC)
    7. cleanup: remove r3 from GAC



testAll.bat

:: Test a modified source of the Cobra compiler. 
:: Precondition: 
::   "cc\Source\bin\" : contains this file
::   "cc\Tests\" : contains the test programs for -testify
::   "cobra.bat" : calls the compiler1 -- the installed "cobra.exe"
::   "call gacutil" : calls the proper "gacutil.exe"

@setlocal
@set Version=0.0.3116
@set bc= -c -ert -turbo -debug:pdbonly  cobra.cobra -files:files-to-compile.text
@set bsl= -bsl -out:Cobra.Core.dll -turbo -debug:pdbonly  -key-file:Cobra.Core\Cobra.Core.snk Cobra.Core\AssemblyAttrs.cobra

@cd %~dp0
@cd ..
:: now "cc\Source\" is the current dir

@echo.
@echo ==[1]== create "NewSnapshot" dir ====
@if exist NewSnapshot rd NewSnapshot /s/q
@xcopy Cobra.Core\*.*   NewSnapshot\Cobra.Core\*.*  /s/e/q

@echo.
@echo ==[2]== with compiler1 : build compiler2 (in dir "NewSnapshot") ====
call cobra.bat -out:NewSnapshot\cobra.exe  %bc%  -embed-version:%Version%.2

@echo.
@echo ==[3]== with compiler2 : build compiler3 (in dir "Source") ====
NewSnapshot\cobra.exe -out:cobra.exe  %bc%  -embed-version:%Version%.3

@echo.
@echo ==[4]== with compiler3 : build runtimelib3 (in dir "Source") ====
cobra.exe  %bsl%  -embed-version:%Version%.3

@echo.
@echo ==[5]== install runtimelib3 in GAC ====
call gacutil -i Cobra.Core.dll
call gacutil -l Cobra.Core

@echo.
@echo ==[6]== with compiler3 (and runtimelib3 in GAC) : run tests  ====
@type nul > r-testify-failures.text
cobra.exe  -testify  ..\Tests
@echo.
@echo _____________________________________________________
type r-testify-failures.text
@echo _____________________________________________________

@echo.
@echo ==[7]== cleanup: remove runtimelib3 from GAC ====
call gacutil -u Cobra.Core,Version=%Version%.3
call gacutil -l Cobra.Core

Note: See TracTickets for help on using tickets.