Are aliases supposed to work in (Alias)QualifiedName
s?
#67368
-
Take a look at the following code: using MySystem = System;
var emptyString = global::MySystem.String.Empty; As of now, it doesn't compile: https://sharplab.io/#v2:EYLgtghglgdgNAFxANwKYCcoDMCecAmIA1AD4ACADAAQCyOZAjFQLxWMDcAsAFA/IToqqMAAcEOAMoJMMAOYsqsgDYB7YBCUgQdRgDopM2boCio8eyA= However, I am not sure if it is a bug or an expected behaviour. From one point of view alias is just a placeholder for the thing it understudies, so |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Compiler behavior seems to be correct here. The point of an alias is to look up something in the global namespace of that set of references. The set of references has no 'MySystem', so it errors. The 'MySystem' alias isn't something found in something else. It's for simple name lookup within it's lexical scope. You don't have a simple name here, so it shouldn't even be referenced.
Definitely not how the language sees it :) It's not like there's a prepass replacing that identifier with the thing on the RHS. Instead, names are looked up. If they happen to bind to the alias using that lookup logic, at that point you can consider it to have the meaning of the thing on the RHS. |
Beta Was this translation helpful? Give feedback.
Compiler behavior seems to be correct here. The point of an alias is to look up something in the global namespace of that set of references. The set of references has no 'MySystem', so it errors. The 'MySystem' alias isn't something found in something else. It's for simple name lookup within it's lexical scope. You don't have a simple name here, so it shouldn't even be referenced.
Definitely not how the language sees it :)
It's not like there's a prepass replacing that identifier with the thing on the RHS. Instead, names are looked up. If they happen to bind to the alias using that lookup logic, at that poi…