winglang / winglang/wing

Proposal: implicit scope for any function

Open
#287 10 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

📐 language-design
Dominant language
TypeScript
Stars
5.4k
Forks
215
Avg merge
2h 9m
Merged PRs (30d)
27

Description

I am wondering if the notion of implicit scopes, which we already have for resource initializers, can be extended to methods/functions as well.

So basically any method/functions/constructor that has a first argument called scope of type Construct is called without explicitly specifying the scope, and can be customised with "in SCOPE" syntax of course.

This comes up quite a lot, especially in static factory methods. It means that any code that runs in wing always have access to the parent scope that called it. Something that we struggled with in the CDK quite a lot.

The follow up question is what happens in Wing code. If I want to access scope from any method/function, does it mean the compiler will implicitly include an additional first parameter to the function signature. That's a breaking change...

Perhaps all wing functions should always have an implicit scope as the first argument? Don't kill me!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the existing implicit-scope behavior for resource initializers, then compare it with method, function, and constructor calls that take a first scope argument of type Construct. Define the semantics for Wing code, including whether scope becomes an implicit parameter and how in SCOPE customization works; the issue is done when these rules and their breaking-change implications are specified.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.