Skip to content

Commit

Permalink
Merge pull request #1344 from GaijinEntertainment/method-call-like-sy…
Browse files Browse the repository at this point in the history
…ntax

this can look like method call
  • Loading branch information
borisbat authored Oct 31, 2024
2 parents f35dded + 5f34ee2 commit c46a2f5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
12 changes: 12 additions & 0 deletions examples/test/misc/hello_world.das
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,15 @@ def test_while ( cond : bool ) {
/////////
// piping

def take_mks ( a : Mks ) {
debug(a);
}

def take_mks_and_int ( a : Mks; b : int ) {
debug(a);
debug(b);
}

def take_anything ( a ) {
debug(a);
}
Expand Down Expand Up @@ -360,6 +369,9 @@ def test_pipes() {
print("this is lambda which takes 2 arguments");
return 13; // and returns value
};
var mks = Mks();
mks.take_mks(); // method-like call syntax
mks.take_mks_and_int(13); // method-like call syntax
}

///////////
Expand Down
26 changes: 25 additions & 1 deletion src/ast/ast_infer_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3072,7 +3072,31 @@ namespace das {
if ( expr->argumentsFailedToInfer ) {
auto blockT = expr->arguments[0]->type;
if ( !blockT ) {
// no go, no block
if ( expr->isInvokeMethod && expr->arguments[0]->rtti_isField() ) {
auto eField = static_pointer_cast<ExprField>(expr->arguments[0]);
if ( eField->value->type ) { // it inferred, but field not found
bool allOtherInferred = true; // we check, if all other arguments inferred
for ( size_t i=2; i!=expr->arguments.size(); ++i ) {
if ( !expr->arguments[i]->type ) {
allOtherInferred = false;
break;
}
}
if ( allOtherInferred ) {
// we build _::{field.name} ( field, arg1, arg2, ... )
auto newCall = make_smart<ExprCall>(expr->at, "__::" + eField->name);
newCall->arguments.push_back(eField->value->clone());
for ( size_t i=2; i!=expr->arguments.size(); ++i ) {
newCall->arguments.push_back(expr->arguments[i]->clone());
}
auto fcall = inferFunctionCall(newCall.get(), InferCallError::tryOperator); // we infer it
if ( fcall != nullptr ) {
reportAstChanged();
return newCall;
}
}
}
}
} else if ( !blockT->isGoodBlockType() && !blockT->isGoodFunctionType() && !blockT->isGoodLambdaType() ) {
// no go, not a good block
} else if ( expr->arguments.size()-1 != blockT->argTypes.size() ) {
Expand Down

0 comments on commit c46a2f5

Please sign in to comment.