[nem-bug] [Nemerle 0000572]: I cannot understand conversion between int and char

feedback at nemerle.org feedback at nemerle.org
Tue Nov 15 19:20:19 CET 2005


A NOTE has been added to this issue.
======================================================================
<http://nemerle.org/bugs/view.php?id=572> 
======================================================================
Reported By:                ymatsu
Assigned To:                
======================================================================
Project:                    Nemerle
Issue ID:                   572
Category:                   Compiler (type engine)
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     new
======================================================================
Date Submitted:             11-15-2005 19:12 CET
Last Modified:              11-15-2005 19:20 CET
======================================================================
Summary:                    I cannot understand conversion between int and char
Description: 
def x:int = 'a';

doesn't work.
Compiler message is

parser.n:5:9:5:12: error: expected int, got char in type-enforced
expression: System.Char is not a subtype of System.Int32 [simple require]

How can I convert int from char, char from int?
======================================================================

----------------------------------------------------------------------
 nazgul - 11-15-05 19:20 
----------------------------------------------------------------------
You must use explicit cast to convert from char to int:

def x = 'a' :> int;

We do not allow chars to be automatically converted to ints, because
treating chars as ints is usually a mistake and the mapping is not clear
(i.e. for unicode characters). Using :> (runtime cast) instead of :
(staitc, compile-time type check) forces conversion.

Issue History
Date Modified  Username       Field                    Change              
======================================================================
11-15-05 19:12 ymatsu         New Issue                                    
11-15-05 19:20 nazgul         Note Added: 0001028                          
======================================================================




More information about the bugs mailing list