Anonymous functions in Scala should not be filtered out (#912)

diff --git a/org.jacoco.core.test.validation.scala/src/org/jacoco/core/test/validation/scala/ScalaAnonymousFunctionTest.java b/org.jacoco.core.test.validation.scala/src/org/jacoco/core/test/validation/scala/ScalaAnonymousFunctionTest.java
new file mode 100644
index 0000000..676e3d9
--- /dev/null
+++ b/org.jacoco.core.test.validation.scala/src/org/jacoco/core/test/validation/scala/ScalaAnonymousFunctionTest.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Evgeny Mandrikov - initial API and implementation
+ *
+ *******************************************************************************/
+package org.jacoco.core.test.validation.scala;
+
+import org.jacoco.core.test.validation.ValidationTestBase;
+import org.jacoco.core.test.validation.scala.targets.ScalaAnonymousFunctionTarget;
+
+/**
+ * Test of anonymous functions.
+ */
+public class ScalaAnonymousFunctionTest extends ValidationTestBase {
+
+    public ScalaAnonymousFunctionTest() {
+        super(ScalaAnonymousFunctionTarget.class);
+    }
+
+}
diff --git a/org.jacoco.core.test.validation.scala/src/org/jacoco/core/test/validation/scala/targets/ScalaAnonymousFunctionTarget.scala b/org.jacoco.core.test.validation.scala/src/org/jacoco/core/test/validation/scala/targets/ScalaAnonymousFunctionTarget.scala
new file mode 100644
index 0000000..02fefc5
--- /dev/null
+++ b/org.jacoco.core.test.validation.scala/src/org/jacoco/core/test/validation/scala/targets/ScalaAnonymousFunctionTarget.scala
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Evgeny Mandrikov - initial API and implementation
+ *
+ *******************************************************************************/
+package org.jacoco.core.test.validation.scala.targets
+
+import org.jacoco.core.test.validation.targets.Stubs.{exec, noexec, nop}
+
+/**
+ * Test target for anonymous functions.
+ */
+object ScalaAnonymousFunctionTarget {
+
+  def main(args: Array[String]): Unit = {
+
+    exec(() => {
+      nop() // assertFullyCovered()
+    })
+
+    noexec(() => {
+      nop() // assertNotCovered()
+    })
+
+  }
+
+}
diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/SyntheticFilterTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/SyntheticFilterTest.java
index 5b0a30b..01b074e 100644
--- a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/SyntheticFilterTest.java
+++ b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/SyntheticFilterTest.java
@@ -57,6 +57,17 @@
 	}
 
 	@Test
+	public void should_not_filter_Scala_anonymous_functions() {
+		final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION,
+				Opcodes.ACC_SYNTHETIC, "$anonfun$main$1", "()V", null, null);
+		m.visitInsn(Opcodes.RETURN);
+
+		filter.filter(m, context, output);
+
+		assertIgnored();
+	}
+
+	@Test
 	public void should_not_filter_method_with_suffix_default_in_kotlin_classes() {
 		final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION,
 				Opcodes.ACC_SYNTHETIC | Opcodes.ACC_BRIDGE, "example$default",
diff --git a/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/SyntheticFilter.java b/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/SyntheticFilter.java
index 46d4e6e..87dde91 100644
--- a/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/SyntheticFilter.java
+++ b/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/SyntheticFilter.java
@@ -29,6 +29,10 @@
 			return;
 		}
 
+		if (methodNode.name.startsWith("$anonfun$")) {
+			return;
+		}
+
 		if (KotlinGeneratedFilter.isKotlinClass(context)) {
 			if (KotlinDefaultArgumentsFilter
 					.isDefaultArgumentsMethod(methodNode)) {
diff --git a/org.jacoco.doc/docroot/doc/changes.html b/org.jacoco.doc/docroot/doc/changes.html
index a8e69ce..acc114f 100644
--- a/org.jacoco.doc/docroot/doc/changes.html
+++ b/org.jacoco.doc/docroot/doc/changes.html
@@ -40,6 +40,9 @@
       and containing arguments of type <code>long</code> or <code>double</code>
       should be filtered out during generation of report
       (GitHub <a href="https://github.com/jacoco/jacoco/issues/908">#908</a>).</li>
+  <li><code>synthetic</code> methods that contain bodies of anonymous functions
+      in Scala should not be ignored
+      (GitHub <a href="https://github.com/jacoco/jacoco/issues/912">#921</a>).</li>
 </ul>
 
 <h2>Release 0.8.4 (2019/05/08)</h2>