[nem-bug] [Nemerle 0000503]: Cannot do type match on 'a

feedback at nemerle.org feedback at nemerle.org
Mon May 22 18:03:49 CEST 2006


The following issue has been CLOSED
======================================================================
<http://nemerle.org/bugs/view.php?id=503> 
======================================================================
Reported By:                nazgul
Assigned To:                malekith
======================================================================
Project:                    Nemerle
Issue ID:                   503
Category:                   Compiler
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     closed
Resolution:                 fixed
Fixed in Version:           
======================================================================
Date Submitted:             08-07-2005 11:58 CEST
Last Modified:              05-22-2006 18:03 CEST
======================================================================
Summary:                    Cannot do type match on 'a
Description: 
      def better_to_string ['a] (x : 'a) {
        match (x) {
          | str is string => "\"" + str + "\""
          | ch is char => "'" + ch.ToString + "'"
          | _ => x.ToString ()
        }
      }
      
======================================================================

----------------------------------------------------------------------
 malekith - 08-23-05 17:41 
----------------------------------------------------------------------
This doesn't work in C# too:
foo.cs(5,20): error CS0030: Cannot convert type 'T' to 'char'

class C {
  public static void foo<T> (T x)
  {
    if (x is char) {
          char c = (char)(x);
    }
  }
}

however (char)((object)x) works. It also works in Nemerle (match (x :
object) ...)

I'm not sure if we want to do better than C# (there probably is some
reason this is forbidden).

----------------------------------------------------------------------
 nazgul - 08-30-05 14:26 
----------------------------------------------------------------------
Funny, this link gives example of is on generic parameters:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/csharp_generics.asp

but mono and beta1 gives the mentioned error. Is it still true with CTP?
Maybe we should submit bugreport to MS (at least the docs are wrong)?

----------------------------------------------------------------------
 nazgul - 08-30-05 14:35 
----------------------------------------------------------------------
Ah, the problem is with cast, not typecheck. Well, I see no reason why
casting is forbidden (especially that they are allowing both 'is' and
'as'). And taking the 'as' example, I think we should support the code
from the bug - actually it is our version of C# 'as'. 

>From the mentioned link:
"The compiler lets you explicitly cast generic type parameters to any
other interface, but not to a class:"

A bit odd. I will google more to find why they forbid it..., but this
looks like a broken design or more likely some great pain because of lack
of distinction between : and :>

----------------------------------------------------------------------
 nazgul - 09-10-05 12:55 
----------------------------------------------------------------------
With our distinction of : and :> there are no reasons why this should not
be supported.

----------------------------------------------------------------------
 malekith - 05-08-06 12:01 
----------------------------------------------------------------------
Reolved on trunk, as of r6245.

Issue History
Date Modified  Username       Field                    Change              
======================================================================
08-07-05 11:58 nazgul         New Issue                                    
08-23-05 17:41 malekith       Note Added: 0000902                          
08-23-05 17:41 malekith       Status                   new => feedback     
08-23-05 17:41 malekith       Summary                  Cannot do type match on
'a => Cannot do type match on \'a
08-23-05 17:41 malekith       Description Updated                          
08-23-05 17:41 malekith       Additional Information Updated                    
08-30-05 14:26 nazgul         Note Added: 0000938                          
08-30-05 14:35 nazgul         Note Added: 0000940                          
09-10-05 12:55 nazgul         Note Added: 0000953                          
09-10-05 12:55 nazgul         Status                   feedback => confirmed
09-10-05 12:55 nazgul         Summary                  Cannot do type match on
'a => Cannot do type match on \'a
09-10-05 12:55 nazgul         Description Updated                          
09-10-05 12:55 nazgul         Additional Information Updated                    
05-08-06 12:01 malekith       Status                   confirmed => resolved
05-08-06 12:01 malekith       Resolution               open => fixed       
05-08-06 12:01 malekith       Assigned To               => malekith        
05-08-06 12:01 malekith       Note Added: 0001248                          
05-08-06 12:01 malekith       Summary                  Cannot do type match on
'a => Cannot do type match on \'a
05-08-06 12:01 malekith       Description Updated                          
05-08-06 12:01 malekith       Additional Information Updated                    
05-22-06 18:03 nazgul         Status                   resolved => closed  
======================================================================




More information about the bugs mailing list