while this code compiles fine 
    
    
    from strutils import `%`
    type
        Roles = enum
            user,catering,manager,sysadmin
    
    converter toRole(s : string): Roles =
        case s
            of "user":
                return Roles.user
            of "catering":
                return Roles.catering
            of "manager":
                return Roles.manager
            of "sysadmin":
                return Roles.sysadmin
            else:
                raise newException(ValueError, "could not convert string '$#' 
to Roles" % [s])
    

this one does not 
    
    
    from strutils import `%`
    type
        Roles = enum
            user,catering,manager,sysadmin
    
    converter toRole(s : string): Roles =
        case s
            of "user":
                Roles.user
            of "catering":
                Roles.catering
            of "manager":
                Roles.manager
            of "sysadmin":
                Roles.sysadmin
            else:
                raise newException(ValueError, "could not convert string '$#' 
to Roles" % [s])
    

while this also compiles 
    
    
    from strutils import `%`
    type
        Roles = enum
            user,catering,manager,sysadmin
    
    converter toRole(s : string): Roles =
        case s
            of "user":
                Roles.user
            of "catering":
                Roles.catering
            of "manager":
                Roles.manager
            of "sysadmin":
                Roles.sysadmin
            else:
                Roles.sysadmin
    

Isn't it bad to force to write the return explicitly only because one branch of 
the case does not return?

Reply via email to