Skip to content
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

merge queue: embarking dev (ce24a6a), #3468 and #3535 together #3546

Closed
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
34479ea
wip: super calls via new type of call expr
yoav-steinberg Jul 12, 2023
a537283
chore(docs): ci/cd guide (backport #3360) (#3413)
mergify[bot] Jul 13, 2023
72d4d3c
chore: fix topic title (backport #3415) (#3416)
mergify[bot] Jul 13, 2023
20f5e97
fix(docs): post code freeze small issues (backport #3403) (#3420)
mergify[bot] Jul 13, 2023
08a3ace
chore(console): clean version prints to console (backport #3419) (#3424)
mergify[bot] Jul 13, 2023
0de5447
fix(cli): removed duplicate export hook call (backport #3425) (#3429)
mergify[bot] Jul 13, 2023
a07655f
fix(vscode): lsp crashes when a non-spanned diagnostics is encountere…
mergify[bot] Jul 13, 2023
e3da1e5
fix(docs): analytic opt-out env var outdated (backport #3430) (#3433)
mergify[bot] Jul 13, 2023
cc2c8ed
chore: remove release commenter for now (backport #3427) (#3434)
mergify[bot] Jul 13, 2023
6c92e5b
chore(vscode): monada to wing cloud, and remove alpha from ext name (…
mergify[bot] Jul 13, 2023
b55819c
chore(docs): tf-aws cleanup bucket files and inflight docs enhanced (…
mergify[bot] Jul 13, 2023
d722833
fix(cli): display analytics disclaimer only in tty (backport #3439) (…
mergify[bot] Jul 13, 2023
bf4c3b8
chore(docs): update terraform backend guide (backport #3445) (#3446)
mergify[bot] Jul 14, 2023
a8d9d10
chore(repo): disable analytics for canary (backport #3452) (#3453)
mergify[bot] Jul 15, 2023
9abd0ba
wip
yoav-steinberg Jul 15, 2023
0767b48
wip
yoav-steinberg Jul 15, 2023
2b9fbdf
added tests
yoav-steinberg Jul 15, 2023
59d2472
snapshots
yoav-steinberg Jul 15, 2023
31fae41
feat(sdk): adding schedule to awscdk
marciocadev Jul 16, 2023
9f26966
refactoring
marciocadev Jul 16, 2023
82800af
chore(console): disable console analytics for ci (backport #3460) (#3…
mergify[bot] Jul 16, 2023
4960d26
chore(console): remove white spaces from analytics events (backport #…
mergify[bot] Jul 16, 2023
9be103f
revert changes not needed
yoav-steinberg Jul 16, 2023
1b5fdab
chore(docs): modified compiler target code example (backport #3465) (…
mergify[bot] Jul 16, 2023
9dbe1d6
chore(docs): fix examples (backport #3471) (#3472)
mergify[bot] Jul 16, 2023
bb3ffb6
fix(docs): typo in docs (backport #3467) (#3470)
mergify[bot] Jul 16, 2023
2069141
no need to track current class in jsifier (use `this` lookup instead)
yoav-steinberg Jul 16, 2023
86b47b8
reference issue in err message
yoav-steinberg Jul 16, 2023
0d68539
Merge branch 'main' into yoav/super_calls2
yoav-steinberg Jul 16, 2023
5556bd4
fixes after merge from main
yoav-steinberg Jul 16, 2023
0b1e4a2
Merge branch 'dev' into yoav/super_calls2
yoav-steinberg Jul 16, 2023
4d31133
import fixes after merge
yoav-steinberg Jul 16, 2023
f5767d1
updated snapshot after merge
yoav-steinberg Jul 16, 2023
e1d2798
lint
yoav-steinberg Jul 16, 2023
09c3b9d
Merge branch 'dev' into yoav/super_calls2
yoav-steinberg Jul 19, 2023
45e33f2
adding snapshots
marciocadev Jul 19, 2023
2c2313f
Merge branch 'dev' into marciocadev/awscdk-schedule
marciocadev Jul 19, 2023
0925b82
adding tests to awscdk schedule
marciocadev Jul 19, 2023
a98c3e1
refactoring
marciocadev Jul 19, 2023
9a5bef3
refactoring
marciocadev Jul 19, 2023
2779a94
cr: shorter err message
yoav-steinberg Jul 20, 2023
77c979b
cr: err messages
yoav-steinberg Jul 20, 2023
34bff8e
Merge of #3468
mergify[bot] Jul 20, 2023
a9ea0f3
Merge of #3535
mergify[bot] Jul 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions examples/tests/invalid/super_call.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
class A {
method() {
// Acccess super with no base class (in case of preflight there's actually an implicit base class, `std.Resource`, we need to ignore)
super.method();
//^^^^^^ Cannot call super method because class A has no parent
}
}

inflight class InflightA {
method() {
// Access super with no base class
super.method();
//^^^^^^ Cannot call super method because class A has no parent
}
}

class B extends A {
child_method() {
// Access child method through super
super.child_method();
//^^^^^^^^^^^^ super class "A" does not have a method named "child_method"
}

static static_method() {
// super doesn't make sense in static context
super.method();
//^^^^^ Cannot call super method inside of a static method
}
}

// super doesn't make sense in global context
super.do();
//^^ "super" can only be used inside of classes


// Verify correct error message when inflight closure tries to access super (this isn't suported yet see: https://github.com/winglang/wing/issues/3474)
// Once it is, this test should be moved to "valid"
class BaseClass {
inflight m1(): str {
return "base inflight m1";
}
}

bring cloud;
let q = new cloud.Queue();
class ExtendedClass extends BaseClass {
inflight m1(): str {
return "extended inflight m1";
}
get_func(): cloud.Function {
let inflight_closure = inflight (s:str): str => {
return "this: ${this.m1()}, super: ${super.m1()}";
//^^ `super` calls inside inflight closures not supported yet, see: https://github.com/winglang/wing/issues/3474
};
return new cloud.Function(inflight_closure);
}
}
// TODO: uncomment and move to valid tests once this: https://github.com/winglang/wing/issues/3474 is fixed
// let y = new ExtendedClass().get_func();
// test "inflight closure accesses super" {
// assert(y.invoke("") == "this: extended inflight m1, super: base inflight m1");
// }
72 changes: 72 additions & 0 deletions examples/tests/valid/super_call.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
class A {
message: str;

init() {
this.message = "A message from your ancestor";
}
}

class B extends A {
description(): str {
return "B";
}
}

class C extends B {
description(): str {
return "C extends ${super.description()}";
}
}

// This class has no `description` method, so it inherits the one from `B`.
class D extends C {
}

class E extends D {
description(): str {
return "E extends ${super.description()}";
}
}

let e = new E();
// Make sure super calls work and skip anything in the inheritance chain that doesn't have the method
assert(e.description() == "E extends C extends B");

inflight class InflightA {
description(): str {
return "InflightA";
}
}

// Test super calls on inflight classes
inflight class InflightB extends InflightA {
description(): str {
return "InflightB extends ${super.description()}";
}
}

test "super call inflight" {
let b = new InflightB();
assert(b.description() == "InflightB extends InflightA");
}

// Test correct binding when calling a super method
bring cloud;
let b = new cloud.Bucket();
class BaseClass {
inflight do(): str {
return b.get("k"); // BaseClass class required read acceess to b
}
}

class ExtendedClass extends BaseClass {
inflight do(): str {
b.put("k", "value"); // This should require write access to b
return super.do(); // We expect to add binding permissions based on what `super.do()` requires (read)
}
}

let extended = new ExtendedClass();
test "super call sets binding permissions" {
assert(extended.do() == "value");
}
12 changes: 3 additions & 9 deletions libs/tree-sitter-wing/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,20 +380,14 @@ module.exports = grammar({
compiler_dbg_panic: ($) => "😱",
compiler_dbg_env: ($) => seq("🗺️", optional(";")),

_callable_expression: ($) =>
choice(
$.nested_identifier,
$.identifier,
$.call,
$.parenthesized_expression
),

call: ($) =>
prec.left(
PREC.CALL,
seq(field("caller", $.expression), field("args", $.argument_list))
seq(field("caller", choice($.expression, $.super_call)), field("args", $.argument_list))
),

super_call: ($) => seq($._super, ".", field("method", $.identifier)),

argument_list: ($) =>
seq(
"(",
Expand Down
19 changes: 18 additions & 1 deletion libs/wingc/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ pub enum ExprKind {
},
Reference(Reference),
Call {
callee: Box<Expr>,
callee: CalleeKind,
arg_list: ArgList,
},
Unary {
Expand Down Expand Up @@ -557,6 +557,23 @@ pub enum ExprKind {
CompilerDebugPanic,
}

#[derive(Debug)]
pub enum CalleeKind {
/// The callee is any expression
Expr(Box<Expr>),
/// The callee is a method in our super class
SuperCall(Symbol),
}

impl Spanned for CalleeKind {
fn span(&self) -> WingSpan {
match self {
CalleeKind::Expr(e) => e.span.clone(),
CalleeKind::SuperCall(method) => method.span(),
}
}
}

#[derive(Debug)]
pub struct Expr {
/// An identifier that is unique among all expressions in the AST.
Expand Down
7 changes: 5 additions & 2 deletions libs/wingc/src/fold.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
ast::{
ArgList, CatchBlock, Class, ClassField, ElifBlock, Expr, ExprKind, FunctionBody, FunctionDefinition,
ArgList, CalleeKind, CatchBlock, Class, ClassField, ElifBlock, Expr, ExprKind, FunctionBody, FunctionDefinition,
FunctionParameter, FunctionSignature, Interface, InterpolatedString, InterpolatedStringPart, Literal, NewExpr,
Reference, Scope, Stmt, StmtKind, StructField, Symbol, TypeAnnotation, TypeAnnotationKind, UserDefinedType,
},
Expand Down Expand Up @@ -263,7 +263,10 @@ where
},
ExprKind::Reference(reference) => ExprKind::Reference(f.fold_reference(reference)),
ExprKind::Call { callee, arg_list } => ExprKind::Call {
callee: Box::new(f.fold_expr(*callee)),
callee: match callee {
CalleeKind::Expr(expr) => CalleeKind::Expr(Box::new(f.fold_expr(*expr))),
CalleeKind::SuperCall(method) => CalleeKind::SuperCall(f.fold_symbol(method)),
},
arg_list: f.fold_args(arg_list),
},
ExprKind::Unary { op, exp } => ExprKind::Unary {
Expand Down
Loading
Loading