New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A type with a built-in type's name can co-exist. #5537
Comments
Indeed. But only within that lexical scope. If you put the classes into a separate scope, there is no issue: say 'version: ', $*RAKU.version; # v6.d
{
class Quadruped { has $.legs = 4; }
class Rat is Quadruped { has $.head = 1 }
my $num = 1.1;
say '$num.raku: ', $num.raku; # 1.1
say '$num.WHAT: ', $num.WHAT; # (Rat)
my $rat = Rat.new();
say '$rat.WHAT: ', $rat.WHAT; # (Rat)
say '$rat.^parents: ', $rat.^parents; # ((Quadruped))·
}
my Rat $r = 2.2; # see below
dd $r;
Like imports, (almost) everything in Raku is lexically scoped. So yes, you can have a Note that if you would have removed the |
I would tend to close this as a non-issue. Maybe a doc issue would need to be created instead? |
My issue is not that the exception is thrown. My issue is that a |
@0rir Say, you import a module that exports |
It seems to me that we could emit a worry when a core class is masked. But maybe I just secretly like the idea of:
|
Quite a few, especially at different lexical scopes. I take advantage of this in
I get that I'm biased, but that would then require the above module to be called as |
@ab5tract, that was the trend of my thought. @lizmat, given that the class is created in the scope, it seems uncertain that the later container typing would be intended for the built-in type or that @alabamenhu, in this situation the current limitations of
|
That's a mouthful for something that already works. I guess the question is, if someone writes a class name that clashes with a core class name, does Raku need to assume that the programmer did this accidentally, or that the programmer did this intentionally? And of those two, who is going to be more bothered by a warning being issued?
Either way, the person who does this unintentionally will figure it out: be it by warning or error. OTOH, the person who does it intentionally will be annoyed by taking advantage of a feature of Raku: fully lexical scoping. The following is perfectly legal: my $a = 1;
{
my $a = 2;
} We don't warn there as lexical scoping explicit feature of Raku, taking advantage of this is enables the not-so-common (but useful when you need 'em) Obviously, I'm team no-warn. Besides, it's not like the core class Rat { has $.head = 1 }
my $r1 = 2.2;
my Rat $r2 = Rat.new: :1head;
my CORE::Rat $r3 = 2.2;
my Rat $r4 = 2.2; # type check fail The literal 2.2 is equivalent to Where I do think we could produce a better error message is if there are two identically named types in a type check to give a warning about that. For instance, instead of
We could say
For non-core types that get shadowed, we could potentially point to where they originated if such information is still available when the type check fail occurs. |
First I want to say that I think your suggestion of changing the output to reference But I also wanted to contribute a contrary example WRT lexical scoping and types:
EDIT: I should mention that I was actually surprised to see a |
That's because |
Doh! I knew that! ... but apparently just not yesterday :) So for the resolution of this ticket, I support increasing the acuity of the thrown exception as per @alabamenhu's suggestion. |
@ab5tract, although I endorse @alabamenhu's suggested action, it seems insufficient. @alabamenhu, your unintentional may include a symbol which |
The text was updated successfully, but these errors were encountered: