Slate brackets parsing bug

I have the following statement:

SNew(SListView<TSharedPtr<FArtifact>>)
	.ListItemsSource(&ArtifactList)
	.OnGenerateRow_Lambda([](TSharedPtr<FArtifact> artifact, const TSharedRef<STableViewBase>& ownerTable)->TSharedRef<ITableRow>
	{ 
		return SNew(STableRow<TSharedPtr<FArtifact>>, ownerTable)
				[
					SNew(SButton)
					.Text(artifact->Rules.ID)
					.OnClicked_Lambda([artifact]()->FReply{ ULogic::AnalyzeArtifact(*artifact.Get()); return FReply::Handled(); })
				]; 
	})

On compiling I have an error (full log in the attachement), about the left bracket ‘[’ after the “return SNew(STableRow>, ownerTable)” statement was not matched correctly. But, as you can see, it is matched correctly.

If I remove the lambda statement of the Button OnClicked event, everything begins to compile correctly. So, I assume, that the parser is having problem with the lamdas capture list brackets, mistaken them with the slate content brackets.

Yes, this is a known issue with the parser in Visual Studio 2013 (it might be fixed for VS2015). Clang does not have this issue.

A workaround would be to declare your lambda outside of the Slate declarative syntax.

Thank you for the answer! I’ve tried defining the lambda outside of the slate like this:

auto onArtifactButtonClicked = [](TSharedPtr<FArtifact> artifact)->FReply{ ULogic::AnalyzeArtifact(*artifact.Get()); return FReply::Handled(); };

Then used it in the slate:

SNew(SListView<TSharedPtr<FArtifact>>)
	.ListItemsSource(&artifactList)
	.OnGenerateRow_Lambda([onArtifactButtonClicked](TSharedPtr<FArtifact> artifact, const TSharedRef<STableViewBase>& ownerTable)->TSharedRef<ITableRow>
	{ 
		return SNew(STableRow<TSharedPtr<FArtifact>>, ownerTable)
				[
					SNew(SButton)
					.Text(artifact->Rules.ID)
					.OnClicked_Lambda(onArtifactButtonClicked(artifact))
				]; 
	})

But now I have the following compilation error:

c:\program files\epic games\4.7\engine\source\runtime\core\public\delegates\Tuple.h(113): error C2064: term does not evaluate to a function taking 0 arguments

Maybe I’m doing something wrong?

You’ve called the lambda with the parameter artifact, so you’re actually passing the return value of that lambda, FReply, into OnClicked_Lambda.

If you want to bind artifact as a parameter, you’ll have to use the full delegate creation syntax (you can normally avoid this, however we don’t have the Slate syntax sugar setup for lambdas as you typically just capture your data in them rather than use delegate bindings).

SNew(SButton)
.Text(artifact->Rules.ID)
.OnClicked(FOnClicked::CreateLambda(onArtifactButtonClicked, artifact))

Thank you very much for your help! I really appreciate the active support here :slight_smile:

The suggested CreateLambda func hadn’t really worked (got me ‘error C2661: … no overloaded function takes 2 arguments’ at compilation), but the CreateStatic worked just fine.