Project

General

Profile

Actions

Bug #1853

closed

Cannot make constants using upper-case extended characters?

Added by candlerb (Brian Candler) almost 15 years ago. Updated about 13 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.2dev (2009-07-18 trunk 24186) [i686-linux]
Backport:
[ruby-core:24650]

Description

=begin

SCHÖN = 1 # constant
=> 1
ÜBER = 2 # local variable!
=> 2
self.class.constants.grep(/SCH|BER/)
=> [:SCHÖN]
local_variables.grep(/SCH|BER/)
=> [:ÜBER]

I am not sure from the source code whether this is intentional or not.
In parse.c it uses rb_enc_isupper which understands encodings:

     else if (rb_enc_isupper(m[0], enc)) {
         id = ID_CONST;
     }
     else {
         id = ID_LOCAL;

This is in rb_intern3. And yet it is called from rb_intern2 which says:

ID
rb_intern2(const char *name, long len)
{
return rb_intern3(name, len, rb_usascii_encoding());
}

If this is intentional, it seems like an arbitrary restriction. Unicode characters are unambiguously classified into upper-case, lower-case and neither. If they can be used anywhere within an identifier, why not at the start of a constant?
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0