forked from winglang/wing
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(compiler)!: access modifiers for classes, structs, interfaces, e…
…nums (winglang#4591) Wing now supports declaring classes, structs, interfaces, and enums as public using the `pub` access modifier. The default access of all types is now private. This PR also fixes a bug where you could not `bring` modules under the same alias in different files. Closes winglang#4294 Closes winglang#4415 Closes winglang#2763 BREAKING CHANGE: All types are private by default. To make a class, struct, or other declaration accessible to other files, prefix it with the `pub` access modifier. ## Checklist - [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted) - [x] Description explains motivation and solution - [x] Tests added (always) - [x] Docs updated (only required for features) - [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing *By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
- Loading branch information
Showing
41 changed files
with
620 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
bring "./subdir2" as subdir2; | ||
|
||
new subdir2.MyPrivateClass(); | ||
// error: Class "MyPrivateClass" is private | ||
|
||
new subdir2.inner.MyOtherPrivateClass(); | ||
// error: Class "MyOtherPrivateClass" is private | ||
// TODO: error: namespace "inner" is private | ||
// (because it has no public API elements) | ||
|
||
class A impl subdir2.MyPrivateInterface {} | ||
// error: Interface "MyPrivateInterface" is private | ||
|
||
let s = subdir2.MyPrivateStruct {}; | ||
// error: Struct "MyPrivateStruct" is private | ||
|
||
let e = subdir2.MyPrivateEnum.A; | ||
// error: Enum "MyPrivateEnum" is private |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ let x = 5; | |
let y = ["hello", "world"]; | ||
let z = new cloud.Bucket(); | ||
|
||
class Bar { | ||
pub class Bar { | ||
x: num; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
protected struct MyStruct {} | ||
// ^ Structs must be public or private | ||
|
||
protected class MyClass {} | ||
// ^ Classes must be public or private | ||
|
||
protected interface MyInterface {} | ||
// ^ Interfaces must be public or private | ||
|
||
protected enum MyEnum {} | ||
// ^ Enums must be public or private |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
class Foo {} | ||
pub class Foo {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
class Foo {} | ||
pub class Foo {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class MyPrivateClass {} | ||
|
||
struct MyPrivateStruct {} | ||
|
||
enum MyPrivateEnum { A, B } | ||
|
||
interface MyPrivateInterface {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
class MyOtherPrivateClass {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// used by bring_local_normalization.w | ||
|
||
class Bar { | ||
pub class Bar { | ||
pub static bar(): str { | ||
return "bar"; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
struct MyStruct { | ||
pub struct MyStruct { | ||
val: num; | ||
} | ||
|
||
struct MyOtherStruct { | ||
pub struct MyOtherStruct { | ||
data: MyStruct; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
struct MyStruct { | ||
pub struct MyStruct { | ||
val: str; | ||
} | ||
|
||
struct SomeStruct { | ||
pub struct SomeStruct { | ||
foo: str; | ||
} | ||
|
||
class UsesStructInImportedFile { | ||
pub class UsesStructInImportedFile { | ||
someStruct: SomeStruct; | ||
|
||
init() { | ||
this.someStruct = SomeStruct.fromJson({foo: "123"}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
bring math; | ||
|
||
class Q { | ||
pub class Q { | ||
extern "./util.js" static inflight greet(name: str): str; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
class Bar { | ||
bring util; | ||
|
||
pub class Bar { | ||
pub bar(): str { | ||
return "bar"; | ||
} | ||
} | ||
|
||
// this file's sibling, file1.w, also has a class "Foo" | ||
// but this is okay since it's private | ||
class Foo {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
class Widget { | ||
pub class Widget { | ||
pub compute(): num { | ||
return 42; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
enum FavoriteNumbers { | ||
pub enum FavoriteNumbers { | ||
SEVEN, | ||
FORTY_TWO, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
class Util { | ||
pub class Util { | ||
pub static inflight double(msg: str): str { | ||
return "${msg}${msg}"; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.