This is an automated email from the ASF dual-hosted git repository.
joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git
The following commit(s) were added to refs/heads/develop by this push:
new 8cee3fb63 MethodBodySemanticChecker: don't allow an arrow function to
be used with new as a constructor
8cee3fb63 is described below
commit 8cee3fb636fa987e460947da24033b2039f65d42
Author: Josh Tynjala <[email protected]>
AuthorDate: Tue Jan 27 12:06:07 2026 -0800
MethodBodySemanticChecker: don't allow an arrow function to be used with
new as a constructor
---
.../semantics/MethodBodySemanticChecker.java | 4 +++
.../ArrowFunctionCannotBeConstructorProblem.java | 38 ++++++++++++++++++++++
2 files changed, 42 insertions(+)
diff --git
a/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/MethodBodySemanticChecker.java
b/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/MethodBodySemanticChecker.java
index e9bb165c2..6dfc63764 100644
---
a/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/MethodBodySemanticChecker.java
+++
b/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/MethodBodySemanticChecker.java
@@ -2796,6 +2796,10 @@ public class MethodBodySemanticChecker
addProblem(new UnresolvedClassReferenceProblem(call_node,
func_name.getDisplayString()));
}
}
+ else if (name instanceof IArrowFunctionBindNode)
+ {
+ addProblem(new ArrowFunctionCannotBeConstructorProblem(call_node));
+ }
}
/**
diff --git
a/compiler/src/main/java/org/apache/royale/compiler/problems/ArrowFunctionCannotBeConstructorProblem.java
b/compiler/src/main/java/org/apache/royale/compiler/problems/ArrowFunctionCannotBeConstructorProblem.java
new file mode 100644
index 000000000..fc5a7b9dd
--- /dev/null
+++
b/compiler/src/main/java/org/apache/royale/compiler/problems/ArrowFunctionCannotBeConstructorProblem.java
@@ -0,0 +1,38 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.royale.compiler.problems;
+
+import org.apache.royale.compiler.tree.as.IASNode;
+
+/**
+ * Strict semantics diagnostic emitted when the method body
+ * semantic checker detects an attempt to call a non-constructor
+ * instance method as a constructor.
+ */
+public final class ArrowFunctionCannotBeConstructorProblem extends
StrictSemanticsProblem
+{
+ public static final String DESCRIPTION =
+ "Arrow function cannot be used as a constructor.";
+
+ public ArrowFunctionCannotBeConstructorProblem(IASNode site)
+ {
+ super(site);
+ }
+}