-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Make sure language imports are detectable syntactically #11193
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
case Some(bv) => bv | ||
case None => | ||
var c = ctx.outer | ||
while c.importInfo eq ctx.importInfo do c = c.outer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: refactor the logic above into a method?
class Context(...):
/** Returns an outer context that introduces an import clause
*
* For a returned context `ctx`, `ctx.isImportContext == true`.
*/
def outerImportContext: Option[Context] = ???
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as it's used only in one place I think it's better to leave it local
case None => | ||
var c = ctx.outer | ||
while c.importInfo eq ctx.importInfo do c = c.outer | ||
(c.importInfo != null) && c.importInfo.featureImported(feature)(using c) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible that c == null
here, when we get to the very 1st context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, because we will hit NoContext
first
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we have NoContext.outer == null
. So the invariant here seems to be that we never hit NoContext
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, better make that explicit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, NoContext
has a null importInfo, so that will stop the recursion.
Make sure that something is a language import if and only if it looks like one. i.e. is of one of the forms import language.xyz import scala.language.xyz import _root_.scala.language.xyz
67dcc08
to
26a39ca
Compare
Make sure that something is a language import if and only if it
looks like one. i.e. is of one of the forms
This is a pre-requisite for using language imports also during parsing, where we cannot resolve imports.
Using language imports during parsing can make the parser more robust by never considering possibilities that are not enabled bu a language import. For instance, we do not need to get confused with postfix operators.