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

feat(compiler): access modifiers #4133

Merged
merged 71 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
82b4de8
wip
yoav-steinberg Sep 3, 2023
a2c2272
wip
yoav-steinberg Sep 3, 2023
c617540
wip: access modifiers
yoav-steinberg Sep 5, 2023
9437676
wip
yoav-steinberg Sep 5, 2023
a8d4627
wip
yoav-steinberg Sep 7, 2023
e3fb276
wip
yoav-steinberg Sep 7, 2023
175303e
wip
yoav-steinberg Sep 7, 2023
0b49843
wip
yoav-steinberg Sep 7, 2023
9c187a2
wip
yoav-steinberg Sep 7, 2023
9deda88
wip
yoav-steinberg Sep 8, 2023
d2bce2f
wip
yoav-steinberg Sep 8, 2023
011c9da
static support
yoav-steinberg Sep 9, 2023
b2f895b
added test
yoav-steinberg Sep 9, 2023
67c380c
correct env for super call, avoid cascading error for unknown properties
yoav-steinberg Sep 9, 2023
3e2df56
type check return expr even when return statement is misplaced
yoav-steinberg Sep 9, 2023
a14c56f
correctly handle access check to std lib type properties (Array)
yoav-steinberg Sep 10, 2023
4047b04
chuck `pub` in favor of `public`
yoav-steinberg Sep 10, 2023
b3740b0
updated jsifier tests
yoav-steinberg Sep 10, 2023
aefdf4d
handle inner classes
yoav-steinberg Sep 10, 2023
443ad8d
inner classes
yoav-steinberg Sep 10, 2023
d99a36f
wip
yoav-steinberg Sep 10, 2023
c5e7de7
fixed tests (added `public`)
yoav-steinberg Sep 10, 2023
6f62894
added missing `public` to sdk tests
yoav-steinberg Sep 10, 2023
e1d26f4
added access_modifiers test results to snapshot
yoav-steinberg Sep 10, 2023
a34edd6
Merge branch 'main' into yoav/access_modifiers
yoav-steinberg Sep 10, 2023
121fb6c
fixes after merge
yoav-steinberg Sep 10, 2023
8f78f26
cleanup
yoav-steinberg Sep 10, 2023
303050f
fix test
yoav-steinberg Sep 10, 2023
2acf609
no need to pass stmt everywhere, use ctx
yoav-steinberg Sep 10, 2023
30b084c
Merge branch 'main' into yoav/access_modifiers
monadabot Sep 10, 2023
5ac4068
chore: self mutation (e2e-2of2.diff)
monadabot Sep 10, 2023
3d378bb
cr cleanup
yoav-steinberg Sep 11, 2023
eec4ea8
cr
yoav-steinberg Sep 11, 2023
e36efd3
cr fix: `super()` call type checked in place and not in class definit…
yoav-steinberg Sep 12, 2023
e82f9aa
cr fix
yoav-steinberg Sep 12, 2023
86696cd
cr fix: add multi level inheritence test for access_modifiers
yoav-steinberg Sep 12, 2023
cd0fa89
Merge branch 'main' into yoav/access_modifiers
monadabot Sep 12, 2023
6d93c6b
chore: self mutation (build.diff)
monadabot Sep 12, 2023
e1f162b
chore: self mutation (e2e-2of2.diff)
monadabot Sep 12, 2023
d3d1c3c
cr fix: interfaces must be public
yoav-steinberg Sep 12, 2023
53cde2a
Merge branch 'yoav/access_modifiers' of https://github.com/winglang/w…
yoav-steinberg Sep 12, 2023
4c3c9bb
Merge branch 'main' into yoav/access_modifiers
monadabot Sep 12, 2023
9c94c74
chore: self mutation (e2e-2of2.diff)
monadabot Sep 12, 2023
37ca5c3
cr: `internal` not supported yet
yoav-steinberg Sep 12, 2023
011ca6b
Merge branch 'yoav/access_modifiers' of https://github.com/winglang/w…
yoav-steinberg Sep 12, 2023
365ee16
cr: better diag for public requirement of interface implemenations
yoav-steinberg Sep 12, 2023
5e7c8c7
cr: doc updates
yoav-steinberg Sep 12, 2023
b5c351f
Merge branch 'main' into yoav/access_modifiers
monadabot Sep 12, 2023
76701cd
chore: self mutation (build.diff)
monadabot Sep 12, 2023
64d6c28
doc update
yoav-steinberg Sep 12, 2023
dcdfb38
Merge branch 'yoav/access_modifiers' of https://github.com/winglang/w…
yoav-steinberg Sep 12, 2023
50e4127
test importing JSII access modifiers
yoav-steinberg Sep 14, 2023
5223a6b
access modifiers and method overriding
yoav-steinberg Sep 14, 2023
ace222d
Merge branch 'main' into yoav/access_modifiers
yoav-steinberg Sep 14, 2023
20d808d
fix after merge
yoav-steinberg Sep 14, 2023
584fdfc
Merge branch 'main' into yoav/access_modifiers
monadabot Sep 14, 2023
23ac3bf
chore: self mutation (e2e-2of2.diff)
monadabot Sep 14, 2023
2870580
fixed tests
yoav-steinberg Sep 14, 2023
41a5097
Merge branch 'yoav/access_modifiers' of https://github.com/winglang/w…
yoav-steinberg Sep 14, 2023
21481d6
rename test files to be main
yoav-steinberg Sep 14, 2023
7bb9100
Merge branch 'main' into yoav/access_modifiers
monadabot Sep 14, 2023
b64fda4
chore: self mutation (build.diff)
monadabot Sep 14, 2023
fa03bed
chore: self mutation (e2e-2of2.diff)
monadabot Sep 14, 2023
11ed9d4
`public` -> `pub`
yoav-steinberg Sep 14, 2023
fc2ef10
Merge branch 'yoav/access_modifiers' of https://github.com/winglang/w…
yoav-steinberg Sep 14, 2023
cdb56c5
Merge branch 'main' into yoav/access_modifiers
monadabot Sep 14, 2023
581d66d
chore: self mutation (build.diff)
monadabot Sep 14, 2023
fcec011
chore: self mutation (e2e-2of2.diff)
monadabot Sep 14, 2023
01c93f1
snapshots
yoav-steinberg Sep 14, 2023
252d539
Merge branch 'yoav/access_modifiers' of https://github.com/winglang/w…
yoav-steinberg Sep 14, 2023
97adb3e
removed ignored/generated file
yoav-steinberg Sep 15, 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
100 changes: 100 additions & 0 deletions examples/tests/invalid/access_modifiers.w
Chriscbr marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
class Foo {
protected protected_field: str;
private_field: str;
public public_field: str;
yoav-steinberg marked this conversation as resolved.
Show resolved Hide resolved

init() {
this.protected_field = "hello";
this.private_field = "world";
this.public_field = "!";
}

method() {
// All of these are valid
log(this.protected_field);
log(this.private_field);
log(this.public_field);
this.public_method();
this.protected_method();
this.private_method();

class InnerFoo {
method(f: Foo) {
// Check access from inner class
log(f.protected_field);
log(f.private_field);
log(f.public_field);
}
}
}

public public_method() {}
protected protected_method() {}
private_method() {}

public static public_static_method() {}
protected static protected_static_method() {}
static private_static_method() {}
}

class Bar extends Foo {
yoav-steinberg marked this conversation as resolved.
Show resolved Hide resolved
method() {
// Check protected access
log(this.protected_field);
log(this.private_field);
// ^ Cannot access private member
log(this.public_field);
this.public_method();
this.protected_method();
this.private_method();
// ^ Cannot access private member
}

static static_method() {
// Check static protected access
Foo.public_static_method();
Foo.protected_static_method();
Foo.private_static_method();
// ^ Cannot access private member
}
}

let foo = new Foo();
// Chck access from non class
log(foo.protected_field);
// ^ Cannot access protected member
log(foo.private_field);
// ^ Cannot access private member
log(foo.public_field);
Foo.public_static_method();
Foo.protected_static_method();
// ^ Cannot access protected member
Foo.private_static_method();
// ^ Cannot access private member

// Check access from non child class (protected is not allowed)
class BarBar {
method() {
log(foo.protected_field);
// ^ Cannot access protected member
log(foo.private_field);
// ^ Cannot access private member
log(foo.public_field);
foo.public_method();
foo.protected_method();
// ^ Cannot access protected member
foo.private_method();
// ^ Cannot access private member
}

static static_method() {
Foo.public_static_method();
Foo.protected_static_method();
// ^ Cannot access protected member
Foo.private_static_method();
// ^ Cannot access private member
}
}

// TODO: check jsii imported access modifiers
// TODO: add tests and implement checks for overriding methods with different access modifiers
2 changes: 1 addition & 1 deletion examples/tests/sdk_tests/function/logging.w
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
bring cloud;

class Util {
extern "./logging.js" static inflight logging(): void;
extern "./logging.js" public static inflight logging(): void;
}

let f1 = new cloud.Function(inflight (input: str): void => {
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/sdk_tests/queue/set_consumer.w
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Predicate {
this.c = c;
}

inflight test(): bool{
public inflight test(): bool{
return this.c.peek() == 2;
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/sdk_tests/topic/on_message.w
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Predicate {
this.c = c;
}

inflight test(): bool{
public inflight test(): bool{
return this.c.peek() == 10;
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/sdk_tests/util/sleep.w
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
bring util;

class JSHelper {
extern "./sleep-helper.js" static inflight getTime(): num;
extern "./sleep-helper.js" public static inflight getTime(): num;
}

let oneHundredMiliseconds = 0.1s;
Expand Down
4 changes: 2 additions & 2 deletions examples/tests/sdk_tests/util/uuidv4.w
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
bring util;

class JSHelper {
extern "./uuidv4-helper.js" static validateUUIDv4(uuidv4: str): bool;
extern "./uuidv4-helper.js" public static validateUUIDv4(uuidv4: str): bool;
}

let data = util.uuidv4();
assert(JSHelper.validateUUIDv4(data) == true);

class JSHelperInflight {
extern "./uuidv4-helper.js" static inflight validateUUIDv4(uuidv4: str): bool;
extern "./uuidv4-helper.js" public static inflight validateUUIDv4(uuidv4: str): bool;
}

test "inflight uuidv4" {
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/sdk_tests/util/wait-until.w
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ bring cloud;
bring util;

class JSHelper {
extern "./sleep-helper.js" static inflight getTime(): num;
extern "./sleep-helper.js" public static inflight getTime(): num;
}

let invokeCounter = new cloud.Counter();
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/sdk_tests/website/website.w
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let w = new cloud.Website(path: "./website");
let config = Json { json: 1 };

class Util {
extern "../external/fs.js" static readFile(path: str): str;
extern "../external/fs.js" public static readFile(path: str): str;
}

let indexFile = Util.readFile("./website/website/index.html");
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/valid/baz.w
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// used by bring_local_normalization.w

class Baz {
static baz(): str {
public static baz(): str {
return "baz";
}
}
10 changes: 5 additions & 5 deletions examples/tests/valid/call_static_of_myself.w
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
class Foo {
static inflight foo(): num { return 1; }
public static inflight foo(): num { return 1; }
static inflight bar(): num { return Foo.foo(); }

inflight callThis(): num {
public inflight callThis(): num {
return Foo.bar();
}

}

inflight class Bar {
static bar(): num { return 2; }
public static bar(): num { return 2; }

callThis(): num {
public callThis(): num {
return Bar.bar();
}
}
Expand All @@ -20,7 +20,7 @@ let foo = new Foo();

test "test" {
class Zoo {
static zoo(): num { return 3; }
public static zoo(): num { return 3; }
}

let bar = new Bar();
Expand Down
4 changes: 2 additions & 2 deletions examples/tests/valid/calling_inflight_variants.w
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ class Foo {
}
}

inflight callFn(x: bool): num {
public inflight callFn(x: bool): num {
// partialFn could be an inflight function created during preflight or inflight,
// so we have to code-generate this to work for both cases
let partialFn = this.makeFn(x);
return partialFn();
}

inflight callFn2(): void {
public inflight callFn2(): void {
// now we call inflight1 and inflight2 directly which know they are handler classes
let one = this.inflight1();
let two = this.inflight2();
Expand Down
6 changes: 3 additions & 3 deletions examples/tests/valid/capture_reassigable_class_field.w
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ class KeyValueStore {
this.onUpdateCallback = inflight (k: str) => {};
}

onUpdate(fn: inflight (str):void){
public onUpdate(fn: inflight (str):void){
this.onUpdateCallback = fn;
}

inflight get(key: str): Json {
public inflight get(key: str): Json {
this.onUpdateCallback(key);
return this.bucket.getJson(key);
}
inflight set(key: str, value: Json): void {
public inflight set(key: str, value: Json): void {
this.bucket.putJson(key, value);
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/tests/valid/capture_resource_with_no_inflight.w
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
bring cloud;

class A {
field: str;
public field: str;
counter: cloud.Counter;

init() {
Expand All @@ -13,7 +13,7 @@ class A {
this.counter.inc();
}

inflight bar() { }
public inflight bar() { }
}

let a = new A();
Expand Down
4 changes: 2 additions & 2 deletions examples/tests/valid/capture_tokens.w
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ class MyResource {
api: cloud.Api;
url: str;

extern "./url_utils.js" static inflight isValidUrl(url: str): bool;
extern "./url_utils.js" public static inflight isValidUrl(url: str): bool;

init() {
this.api = new cloud.Api();
this.url = this.api.url;
}

inflight foo() {
public inflight foo() {
assert(MyResource.isValidUrl(this.url));
assert(MyResource.isValidUrl(this.api.url));
}
Expand Down
22 changes: 11 additions & 11 deletions examples/tests/valid/class.w
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ new C1();

// class with init and no arguments
class C2 {
x: num;
public x: num;
init() {
this.x = 1;
}
Expand All @@ -16,8 +16,8 @@ assert(c2.x == 1);

// class with init and arguments
class C3 {
x: num;
y: num;
public x: num;
public y: num;
init(a: num, b: num) {
this.x = a;
if true {
Expand All @@ -31,19 +31,19 @@ assert(c3.y == 2);

// class with static method and no init
class C4 {
static m():num {return 1;}
public static m():num {return 1;}
}
assert(C4.m() == 1);

// class with inflight field
class C5 {
inflight x: num;
inflight var y: num;
public inflight x: num;
public inflight var y: num;
inflight init() {
this.x = 123;
this.y = 321;
}
inflight set(b: num) {
public inflight set(b: num) {
this.y = b;
}
}
Expand All @@ -57,14 +57,14 @@ test "access inflight field" {
}

class Person {
name: str;
public name: str;
init(name: str) {
this.name = name;
}
}

class Student extends Person {
major: str;
public major: str;

init(name: str, major: str) {
super(name);
Expand All @@ -73,7 +73,7 @@ class Student extends Person {
}

class PaidStudent extends Student {
hrlyWage: num;
public hrlyWage: num;
init(name: str, major: str, hrlyWage: num) {
super(name, major);
this.hrlyWage = hrlyWage;
Expand Down Expand Up @@ -103,7 +103,7 @@ test "devived class init body happens after super" {

// Inflight inheritence
inflight class A {
sound: str;
public sound: str;

inflight init(sound: str) {
this.sound = sound;
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/valid/closure_class.w
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class MyClosure {
inflight another(): str {
public inflight another(): str {
return "hello";
}

Expand Down
6 changes: 3 additions & 3 deletions examples/tests/valid/double_reference.w
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ class Foo {
initCount.inc();
}

inflight method() { }
public inflight method() { }
}

class Bar {
foo: Foo;
public foo: Foo;
init() {
this.foo = new Foo();
}

inflight callFoo() {
public inflight callFoo() {
this.foo.method();
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/valid/doubler.w
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let fn = new Doubler(inflight (m: str): str => {

class Doubler2 {
// TODO: make into a static method - see https://github.com/winglang/wing/issues/2583
makeFunc(handler: inflight (num): num): cloud.Function {
public makeFunc(handler: inflight (num): num): cloud.Function {
return new cloud.Function(inflight (x: str): str => {
let xStr = num.fromStr(x);
let y = handler(xStr);
Expand Down
Loading