Skip to content

Commit

Permalink
[error] Reject static mutators in the parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
pfusik committed Nov 14, 2023
1 parent 6b7f918 commit 2afc4f9
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 17 deletions.
5 changes: 3 additions & 2 deletions Parser.fu
Original file line number Diff line number Diff line change
Expand Up @@ -849,8 +849,9 @@ public class FuParser : FuLexer

void ParseMethod!(FuMethod! method)
{
method.IsMutator = Eat(FuToken.ExclamationMark);
Expect(FuToken.LeftParenthesis);
if (method.CallType != FuCallType.Static)
method.IsMutator = Eat(FuToken.ExclamationMark);
ExpectOrSkip(FuToken.LeftParenthesis);
if (!See(FuToken.RightParenthesis)) {
do {
FuCodeDoc# doc = ParseDoc();
Expand Down
2 changes: 0 additions & 2 deletions Sema.fu
Original file line number Diff line number Diff line change
Expand Up @@ -2088,8 +2088,6 @@ public class FuSema
method.Type = this.Program.System.VoidType;
else
ResolveType(method);
if (method.CallType == FuCallType.Static && method.IsMutator)
ReportError(method, "Static method cannot be mutating ('!')");
for (FuVar!? param = method.Parameters.FirstParameter(); param != null; param = param.NextParameter()) {
ResolveType(param);
if (param.Value != null) {
Expand Down
7 changes: 3 additions & 4 deletions libfut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3780,8 +3780,9 @@ FuCallType FuParser::parseCallType()

void FuParser::parseMethod(FuMethod * method)
{
method->isMutator = eat(FuToken::exclamationMark);
expect(FuToken::leftParenthesis);
if (method->callType != FuCallType::static_)
method->isMutator = eat(FuToken::exclamationMark);
expectOrSkip(FuToken::leftParenthesis);
if (!see(FuToken::rightParenthesis)) {
do {
std::shared_ptr<FuCodeDoc> doc = parseDoc();
Expand Down Expand Up @@ -6179,8 +6180,6 @@ void FuSema::resolveTypes(FuClass * klass)
method->type = this->program->system->voidType;
else
resolveType(method);
if (method->callType == FuCallType::static_ && method->isMutator)
reportError(method, "Static method cannot be mutating ('!')");
for (FuVar * param = method->parameters.firstParameter(); param != nullptr; param = param->nextParameter()) {
resolveType(param);
if (param->value != nullptr) {
Expand Down
7 changes: 3 additions & 4 deletions libfut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4101,8 +4101,9 @@ FuCallType ParseCallType()

void ParseMethod(FuMethod method)
{
method.IsMutator = Eat(FuToken.ExclamationMark);
Expect(FuToken.LeftParenthesis);
if (method.CallType != FuCallType.Static)
method.IsMutator = Eat(FuToken.ExclamationMark);
ExpectOrSkip(FuToken.LeftParenthesis);
if (!See(FuToken.RightParenthesis)) {
do {
FuCodeDoc doc = ParseDoc();
Expand Down Expand Up @@ -6297,8 +6298,6 @@ void ResolveTypes(FuClass klass)
method.Type = this.Program.System.VoidType;
else
ResolveType(method);
if (method.CallType == FuCallType.Static && method.IsMutator)
ReportError(method, "Static method cannot be mutating ('!')");
for (FuVar param = method.Parameters.FirstParameter(); param != null; param = param.NextParameter()) {
ResolveType(param);
if (param.Value != null) {
Expand Down
7 changes: 3 additions & 4 deletions libfut.js
Original file line number Diff line number Diff line change
Expand Up @@ -4244,8 +4244,9 @@ export class FuParser extends FuLexer

#parseMethod(method)
{
method.isMutator = this.eat(FuToken.EXCLAMATION_MARK);
this.expect(FuToken.LEFT_PARENTHESIS);
if (method.callType != FuCallType.STATIC)
method.isMutator = this.eat(FuToken.EXCLAMATION_MARK);
this.expectOrSkip(FuToken.LEFT_PARENTHESIS);
if (!this.see(FuToken.RIGHT_PARENTHESIS)) {
do {
let doc = this.#parseDoc();
Expand Down Expand Up @@ -6614,8 +6615,6 @@ export class FuSema
method.type = this.program.system.voidType;
else
this.#resolveType(method);
if (method.callType == FuCallType.STATIC && method.isMutator)
this.reportError(method, "Static method cannot be mutating ('!')");
for (let param = method.parameters.firstParameter(); param != null; param = param.nextParameter()) {
this.#resolveType(param);
if (param.value != null) {
Expand Down
2 changes: 1 addition & 1 deletion test/error/MethodStaticMutating.fu
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
public static class Test
{
public static bool Run!() //ERROR: Static method cannot be mutating ('!')
public static bool Run!() //ERROR: Expected '(', got '!'
{
return true;
}
Expand Down

0 comments on commit 2afc4f9

Please sign in to comment.