-
-
Notifications
You must be signed in to change notification settings - Fork 648
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
Allow typing expression with added imports and usings. #10537
Comments
Seems more natural to me to have |
I like this idea. This would possibly allow me to avoid defining a new type using |
I agree that we need something like this, but I'm not sure about the exact API. If you want to type two different expressions in the same modified context, the compiler has to create that context both times... What I would prefer from a usage perspective is something like this: function addImports(imports:Array<ImportExpr>, usings:Array<TypePath>, ?ctx:ContextHandle):ContextHandle
function typeExpr(e:Expr, ?ctx:ContextHandle):TypedExpr I didn't think this through yet though. |
Such context handles can go stale, which is a marvelous footgun. I'm wondering whether creating contexts is expensive enough to worry about, because if I'm reading the original PR right, it looks cheap enough. But if not, perhaps something like this would work? function withImports<X>(imports:Array<ImportExpr>, usings:Array<TypePath>, code:()->X):X; The return value is not really needed, but returning values rather than assigning them to captured locals usually plays better with null safety. Used with |
Sorry if I wasn't clear, my concern isn't necessarily performance but the fact that this feature couldn't be combined with anything else. Your |
To my understanding, the passed function would be called synchronously and the original context would be restored after its execution. One can thus compose via nested calls, i.e. it should be fine to do something like |
Ah, I misread that a bit. In that case this seems like a good solution! |
Closed by #10602 I guess? |
This is a bit of a follow up on #3252
While the actual feature discussed there might be a nice addition, what I'm really looking for is a way to type an expression in a modified context (i.e. with additional imports/usings). For that I propose adding a call like the following to
haxe.macro.Context
:That way to define imports/usings is aligned with
Context.defineModule
for consistency.The reason I'm proposing to return
Expr
is to avoid encoding a potentially bigTypedExpr
. Instead a placeholder (much like the one generated viaContext.storeTypedExpr
) would be returned, which still allows retrieving the typed AST viaContext.typeExpr
.The text was updated successfully, but these errors were encountered: