Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(compiler): interface declaration (#1938)
This PR adds support for `interface` according to the [spec](https://docs.winglang.io/reference/spec#34-interfaces). Also in this PR: - [x] Removed interface fields from the spec and our codebase ([slack discussion](https://winglang.slack.com/archives/C048QCN2XLJ/p1680077416200329)). - [x] Removed access modifiers from interface methods (to comply with the spec). - [x] (Very) small refactoring in our grammar.js to rename method return type from `type` to `return_type`. - [x] Removed unused parameter `is_class` from SymbolEnv::new Fixes #123 *By submitting this pull request, I confirm that my contribution is made under the terms of the [Monada Contribution License](https://docs.winglang.io/terms-and-policies/contribution-license.html)*.
- Loading branch information
1 parent
346dca1
commit 7e12b93
Showing
19 changed files
with
583 additions
and
78 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
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,29 @@ | ||
// interface extend loop | ||
interface IA extends IB { | ||
// ^^ Unknown symbol "IB" | ||
} | ||
|
||
interface IB extends IA { | ||
} | ||
|
||
// interface extends interface which doesn't exist | ||
interface IExist extends IDontExist { | ||
// ^^^^^^^^^^ Unknown symbol "IDontExist" | ||
} | ||
|
||
// interface extends class | ||
class ISomeClass { | ||
init(){} | ||
} | ||
interface ISomeInterface extends ISomeClass { | ||
// Interface "ISomeInterface (at ../../examples/tests/invalid/interface.w:21:11)" extends "ISomeClass", which is not an interface | ||
} | ||
|
||
// interface with multiple methods having the same name, different signature | ||
interface IWithSameName { | ||
foo(); | ||
foo(); | ||
// ^^^ Symbol "foo" already defined in this scope | ||
foo(): num; | ||
// ^^^ Symbol "foo" already defined in this scope | ||
} |
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,16 @@ | ||
interface IShape { | ||
// method with a return type | ||
method_1(): str; | ||
// method without a return type | ||
method_2(); | ||
// method with a return type of the interface type | ||
method_3(): IShape; | ||
} | ||
|
||
interface IPointy { | ||
method_2(); | ||
} | ||
|
||
interface ISquare extends IShape, IPointy { | ||
|
||
} |
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
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.