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 4ce1243be Metadata for strict function types
4ce1243be is described below
commit 4ce1243be19492ceeb7de3c1bb2d09607427d9c3
Author: Josh Tynjala <[email protected]>
AuthorDate: Wed Oct 25 15:05:18 2023 -0700
Metadata for strict function types
Ideally, we'll add new syntax for strict function types, but we can't
change the SWF bytecode format (which isstill needed for JS swcs) without
breaking SWF runtime compatibility. With that in mind, the function signatures
need to be stored as metadata with variables/parameters typed as Function in
AS3.
---
.../royale/compiler/config/Configuration.java | 18 +
.../royale/compiler/projects/ICompilerProject.java | 5 +
.../constants/IMetaAttributeConstants.java | 6 +
.../internal/parsing/as/ConfigProcessor.java | 6 +
.../compiler/internal/projects/ASCProject.java | 6 +
.../compiler/internal/projects/RoyaleProject.java | 15 +
.../projects/RoyaleProjectConfigurator.java | 1 +
.../semantics/MethodBodySemanticChecker.java | 327 ++-
.../as/ASStrictFunctionTypesMetadataTests.java | 2583 ++++++++++++++++++++
9 files changed, 2960 insertions(+), 7 deletions(-)
diff --git
a/compiler-common/src/main/java/org/apache/royale/compiler/config/Configuration.java
b/compiler-common/src/main/java/org/apache/royale/compiler/config/Configuration.java
index 78e15f8d1..aa1e2ab15 100644
---
a/compiler-common/src/main/java/org/apache/royale/compiler/config/Configuration.java
+++
b/compiler-common/src/main/java/org/apache/royale/compiler/config/Configuration.java
@@ -6431,4 +6431,22 @@ public class Configuration
inferTypes = b;
}
+ //
+ // 'compiler.allow-strict-function-types'
+ //
+
+ private boolean allowStrictFunctionTypes = false;
+
+ public boolean getAllowStrictFunctionTypes()
+ {
+ return allowStrictFunctionTypes;
+ }
+
+ @Config
+ @Mapping({ "compiler", "allow-strict-function-types" })
+ public void setAllowStrictFunctionTypes(ConfigurationValue cv, boolean b)
+ {
+ allowStrictFunctionTypes = b;
+ }
+
}
diff --git
a/compiler-common/src/main/java/org/apache/royale/compiler/projects/ICompilerProject.java
b/compiler-common/src/main/java/org/apache/royale/compiler/projects/ICompilerProject.java
index ca69ae5e7..ada13a305 100644
---
a/compiler-common/src/main/java/org/apache/royale/compiler/projects/ICompilerProject.java
+++
b/compiler-common/src/main/java/org/apache/royale/compiler/projects/ICompilerProject.java
@@ -282,6 +282,11 @@ public interface ICompilerProject
*/
boolean getAllowPrivateConstructors();
+ /**
+ * @return True if strict function types are allowed and enforced.
+ */
+ boolean getAllowStrictFunctionTypes();
+
/**
* @return True if strict identifier naming is enforced.
*/
diff --git
a/compiler/src/main/java/org/apache/royale/compiler/constants/IMetaAttributeConstants.java
b/compiler/src/main/java/org/apache/royale/compiler/constants/IMetaAttributeConstants.java
index 9412bcb10..2d195f20d 100644
---
a/compiler/src/main/java/org/apache/royale/compiler/constants/IMetaAttributeConstants.java
+++
b/compiler/src/main/java/org/apache/royale/compiler/constants/IMetaAttributeConstants.java
@@ -214,6 +214,12 @@ public interface IMetaAttributeConstants
// [RoyaleAbstract]
static final String ATTRIBUTE_ABSTRACT = "RoyaleAbstract";
+ // [RoyaleFunctionType]
+ static final String ATTRIBUTE_FUNCTION_TYPE = "RoyaleFunctionType";
+ static final String NAME_FUNCTION_TYPE_RETURNS = "returns";
+ static final String NAME_FUNCTION_TYPE_PARAMS = "params";
+ static final String NAME_FUNCTION_TYPE_PARAM_NAME = "paramName";
+
// [RoyalePrivateConstructor]
static final String ATTRIBUTE_PRIVATE_CONSTRUCTOR =
"RoyalePrivateConstructor";
diff --git
a/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/ConfigProcessor.java
b/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/ConfigProcessor.java
index 6f8c7a21c..0236cb84b 100644
---
a/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/ConfigProcessor.java
+++
b/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/ConfigProcessor.java
@@ -177,6 +177,12 @@ public class ConfigProcessor
return false;
}
+ @Override
+ public boolean getAllowStrictFunctionTypes() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
@Override
public boolean getStrictIdentifierNames() {
// TODO Auto-generated method stub
diff --git
a/compiler/src/main/java/org/apache/royale/compiler/internal/projects/ASCProject.java
b/compiler/src/main/java/org/apache/royale/compiler/internal/projects/ASCProject.java
index 6e408f508..8d2becd82 100644
---
a/compiler/src/main/java/org/apache/royale/compiler/internal/projects/ASCProject.java
+++
b/compiler/src/main/java/org/apache/royale/compiler/internal/projects/ASCProject.java
@@ -99,6 +99,12 @@ public class ASCProject extends CompilerProject implements
IASCProject
return false;
}
+ @Override
+ public boolean getAllowStrictFunctionTypes() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
@Override
public boolean getStrictIdentifierNames() {
// TODO Auto-generated method stub
diff --git
a/compiler/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleProject.java
b/compiler/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleProject.java
index 6f29509ee..a3bb1c484 100644
---
a/compiler/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleProject.java
+++
b/compiler/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleProject.java
@@ -2513,6 +2513,21 @@ public class RoyaleProject extends ASProject implements
IRoyaleProject, ICompile
allowPrivateConstructors = allow;
}
+ private boolean allowStrictFunctionTypes = false;
+
+ /**
+ * Indicates if strict function types are allowed and enforced.
+ */
+ @Override
+ public boolean getAllowStrictFunctionTypes()
+ {
+ return allowStrictFunctionTypes;
+ }
+ public void setAllowStrictFunctionTypes(boolean allow)
+ {
+ allowStrictFunctionTypes = allow;
+ }
+
private boolean strictIdentifierNames = false;
/**
diff --git
a/compiler/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleProjectConfigurator.java
b/compiler/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleProjectConfigurator.java
index 7e08de4eb..8c0625a74 100644
---
a/compiler/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleProjectConfigurator.java
+++
b/compiler/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleProjectConfigurator.java
@@ -271,6 +271,7 @@ public class RoyaleProjectConfigurator extends Configurator
project.setAllowImportAliases(configuration.getCompilerAllowImportAliases());
project.setAllowAbstractClasses(configuration.getCompilerAllowAbstractClasses());
project.setAllowPrivateConstructors(configuration.getCompilerAllowPrivateConstructors());
+
project.setAllowStrictFunctionTypes(configuration.getAllowStrictFunctionTypes());
project.setStrictIdentifierNames(configuration.getCompilerStrictIdentifierNames());
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 c8adb1221..ebe11f07f 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
@@ -35,6 +35,7 @@ import static
org.apache.royale.abc.ABCConstants.OP_returnvalue;
import static org.apache.royale.abc.ABCConstants.OP_returnvoid;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.Vector;
import java.util.concurrent.atomic.AtomicInteger;
@@ -53,6 +54,7 @@ import org.apache.royale.compiler.common.ModifiersSet;
import org.apache.royale.compiler.common.ASModifier;
import org.apache.royale.compiler.constants.IASKeywordConstants;
import org.apache.royale.compiler.constants.IASLanguageConstants;
+import org.apache.royale.compiler.constants.IMetaAttributeConstants;
import org.apache.royale.compiler.constants.IASLanguageConstants.BuiltinType;
import org.apache.royale.compiler.definitions.IAccessorDefinition;
import org.apache.royale.compiler.definitions.IClassDefinition;
@@ -62,13 +64,16 @@ import
org.apache.royale.compiler.definitions.IFunctionDefinition;
import org.apache.royale.compiler.definitions.IGetterDefinition;
import org.apache.royale.compiler.definitions.IInterfaceDefinition;
import org.apache.royale.compiler.definitions.INamespaceDefinition;
+import org.apache.royale.compiler.definitions.IParameterDefinition;
import org.apache.royale.compiler.definitions.ISetterDefinition;
import org.apache.royale.compiler.definitions.ITypeDefinition;
import org.apache.royale.compiler.definitions.IVariableDefinition;
+import org.apache.royale.compiler.definitions.metadata.IMetaTag;
import org.apache.royale.compiler.definitions.references.INamespaceReference;
import org.apache.royale.compiler.internal.as.codegen.*;
import org.apache.royale.compiler.internal.definitions.AmbiguousDefinition;
import org.apache.royale.compiler.internal.definitions.VariableDefinition;
+import
org.apache.royale.compiler.internal.definitions.references.ResolvedReference;
import org.apache.royale.compiler.internal.scopes.ASProjectScope;
import org.apache.royale.compiler.problems.*;
import org.apache.royale.compiler.projects.ICompilerProject;
@@ -93,6 +98,7 @@ import org.apache.royale.compiler.tree.as.IScopedNode;
import org.apache.royale.compiler.tree.as.ITypedExpressionNode;
import org.apache.royale.compiler.tree.as.IUnaryOperatorNode;
import org.apache.royale.compiler.tree.as.IVariableNode;
+
import org.apache.royale.compiler.internal.definitions.AccessorDefinition;
import org.apache.royale.compiler.internal.definitions.ClassDefinition;
import org.apache.royale.compiler.internal.definitions.ClassTraitsDefinition;
@@ -238,18 +244,281 @@ public class MethodBodySemanticChecker
addProblem(new
AssignmentInConditionalProblem(SemanticUtils.getNthChild(iNode, 0)));
// Check the assignment's type logic and values.
- ITypeDefinition leftType = null;
if ( binding.getDefinition() != null )
{
IDefinition leftDef = binding.getDefinition();
- leftType = binding.getDefinition().resolveType(project);
-
IASNode rightNode = SemanticUtils.getNthChild(iNode, 1);
-
+
+ ITypeDefinition leftType = leftDef.resolveType(project);
+ if (project.getAllowStrictFunctionTypes() &&
project.getBuiltinType(BuiltinType.FUNCTION).equals(leftType))
+ {
+ IASNode leftNode = (IExpressionNode)
SemanticUtils.getNthChild(iNode, 0);
+ checkFunctionTypeMeta(leftNode, rightNode);
+ }
+
checkImplicitConversion(rightNode, leftType, null);
checkAssignmentValue(leftDef, rightNode);
}
}
+
+ private void checkFunctionTypeMeta(IASNode leftNode, IASNode rightNode)
+ {
+ if (!(leftNode instanceof IExpressionNode) || !(rightNode instanceof
IExpressionNode))
+ {
+ return;
+ }
+ IExpressionNode leftExpression = (IExpressionNode) leftNode;
+ IDefinition resolvedLeft = leftExpression.resolve(project);
+ IMetaTag expectedFunctionTypeMeta =
resolvedLeft.getMetaTagByName(IMetaAttributeConstants.ATTRIBUTE_FUNCTION_TYPE);
+ checkFunctionTypeMeta(expectedFunctionTypeMeta, leftExpression,
rightNode);
+ }
+
+
+ private void checkFunctionTypeMeta(IMetaTag expectedFunctionTypeMeta,
IASNode expectedFunctionTypeSite, IASNode rightNode)
+ {
+ if (!(rightNode instanceof IExpressionNode))
+ {
+ return;
+ }
+
+ IExpressionNode rightExpression = (IExpressionNode) rightNode;
+ IDefinition resolvedRight = rightExpression.resolve(project);
+
+ if (expectedFunctionTypeMeta == null)
+ {
+ return;
+ }
+ boolean checkParams = true;
+
+ String expectedReturnTypeString =
expectedFunctionTypeMeta.getAttributeValue(IMetaAttributeConstants.NAME_FUNCTION_TYPE_RETURNS);
+ ITypeDefinition expectedReturnType =
parseFunctionTypeMetaReturns(expectedReturnTypeString,
expectedFunctionTypeSite);
+
+ String expectedParamsString =
expectedFunctionTypeMeta.getAttributeValue(IMetaAttributeConstants.NAME_FUNCTION_TYPE_PARAMS);
+ List<IParameterDefinition> expectedParams =
parseFunctionTypeMetaParams(expectedParamsString, expectedFunctionTypeSite);
+
+ ITypeDefinition actualReturnType = null;
+ List<IParameterDefinition> actualParams = null;
+ if (resolvedRight instanceof IVariableDefinition)
+ {
+ IVariableDefinition rightVariable = (IVariableDefinition)
resolvedRight;
+ IMetaTag actualFunctionType =
rightVariable.getMetaTagByName(IMetaAttributeConstants.ATTRIBUTE_FUNCTION_TYPE);
+ if (actualFunctionType == null)
+ {
+ String expectedFunctionSignature =
buildFunctionSignatureString(expectedParams, expectedReturnType);
+ addProblem(new
ImplicitCoercionToUnrelatedTypeProblem(rightExpression, "Function",
expectedFunctionSignature));
+ }
+ else
+ {
+ String actualReturnTypeString =
actualFunctionType.getAttributeValue(IMetaAttributeConstants.NAME_FUNCTION_TYPE_RETURNS);
+ actualReturnType =
parseFunctionTypeMetaReturns(actualReturnTypeString, rightExpression);
+
+ String actualParamsString =
actualFunctionType.getAttributeValue(IMetaAttributeConstants.NAME_FUNCTION_TYPE_PARAMS);
+ actualParams = parseFunctionTypeMetaParams(actualParamsString,
rightExpression);
+ }
+ }
+ else if (resolvedRight instanceof IFunctionDefinition)
+ {
+ IFunctionDefinition rightFunction = (IFunctionDefinition)
resolvedRight;
+ actualReturnType = rightFunction.resolveReturnType(project);
+ actualParams = Arrays.asList(rightFunction.getParameters());
+ }
+ if (expectedParams == null || actualParams == null)
+ {
+ checkParams = false;
+ }
+
+ if (checkParams)
+ {
+ boolean lastExpectedIsRest = expectedParams.size() > 0 &&
expectedParams.get(expectedParams.size() - 1).isRest();
+ boolean lastActualIsRest = actualParams.size() > 0 &&
actualParams.get(actualParams.size() - 1).isRest();
+
+ boolean isInvalidSignature = false;
+ if (lastExpectedIsRest && !lastActualIsRest)
+ {
+ isInvalidSignature = true;
+ }
+ if (!isInvalidSignature && actualParams.size() >
expectedParams.size())
+ {
+ for (int i = expectedParams.size(); i < actualParams.size();
i++)
+ {
+ IParameterDefinition actualParam = actualParams.get(i);
+ if (actualParam.isRest() || actualParam.hasDefaultValue())
+ {
+ // allow more actual parameters, as long
+ // as they are optional
+ continue;
+ }
+ isInvalidSignature = true;
+ break;
+ }
+ }
+ if (!isInvalidSignature)
+ {
+ for (int i = 0; i < expectedParams.size(); i++)
+ {
+ if (i >= actualParams.size())
+ {
+ if (!lastActualIsRest)
+ {
+ isInvalidSignature = true;
+ }
+ break;
+ }
+ IParameterDefinition expectedParam = expectedParams.get(i);
+ IParameterDefinition actualParam = actualParams.get(i);
+ if (actualParam.isRest())
+ {
+ break;
+ }
+ ITypeDefinition expectedParamType =
expectedParam.resolveType(project);
+ ITypeDefinition actualParamType =
actualParam.resolveType(project);
+ if (expectedParamType != null
+ && actualParamType != null
+ &&
!project.getBuiltinType(BuiltinType.ANY_TYPE).equals(actualParamType)
+ && !expectedParamType.isInstanceOf(actualParamType,
project))
+ {
+ isInvalidSignature = true;
+ break;
+ }
+ }
+ }
+ if (!isInvalidSignature)
+ {
+ // actual return type must be the same or a subclass
+ // but if expected is void, any return type is accepted
because it will be ignored anyway
+ if (expectedReturnType != null
+ && actualReturnType != null
+ &&
!expectedReturnType.equals(project.getBuiltinType(BuiltinType.VOID))
+ && !actualReturnType.isInstanceOf(expectedReturnType,
project))
+ {
+ isInvalidSignature = true;
+ }
+ }
+ if (isInvalidSignature)
+ {
+ String actualFunctionSignature =
buildFunctionSignatureString(actualParams, actualReturnType);
+ String expectedFunctionSignature =
buildFunctionSignatureString(expectedParams, expectedReturnType);
+ addProblem(new
ImplicitCoercionToUnrelatedTypeProblem(rightExpression,
actualFunctionSignature, expectedFunctionSignature));
+ }
+ }
+ }
+
+ private ITypeDefinition parseFunctionTypeMetaReturns(String returnsString,
IASNode site)
+ {
+ if (returnsString == null)
+ {
+ return null;
+ }
+ String returnsStringTrimmed = returnsString.trim();
+ if (returnsStringTrimmed.length() == 0)
+ {
+ return null;
+ }
+ IDefinition resolvedReturnType =
project.resolveQNameToDefinition(returnsStringTrimmed);
+ if (!(resolvedReturnType instanceof ITypeDefinition))
+ {
+ addProblem(new UnknownTypeProblem(site, returnsStringTrimmed));
+ return null;
+ }
+ return (ITypeDefinition) resolvedReturnType;
+ }
+
+ private List<IParameterDefinition> parseFunctionTypeMetaParams(String
paramsString, IASNode site)
+ {
+ if (paramsString == null)
+ {
+ return null;
+ }
+ List<IParameterDefinition> parsedParams = new
ArrayList<IParameterDefinition>();
+ if (paramsString.trim().length() == 0)
+ {
+ return parsedParams;
+ }
+ String[] splitParamsStrings = paramsString.split(",");
+ for (int i = 0; i < splitParamsStrings.length; i++)
+ {
+ String paramString = splitParamsStrings[i].trim();
+ boolean isRest = paramString.startsWith("...");
+ if (isRest)
+ {
+ paramString = paramString.substring(3);
+ }
+ boolean hasDefaultValue = paramString.endsWith("=");
+ if (hasDefaultValue)
+ {
+ paramString = paramString.substring(0, paramString.length() -
1);
+ }
+ ITypeDefinition resolvedParamType = null;
+ IDefinition resolvedParamDef =
project.resolveQNameToDefinition(paramString);
+ if (resolvedParamDef instanceof ITypeDefinition)
+ {
+ resolvedParamType = (ITypeDefinition) resolvedParamDef;
+ }
+ if (resolvedParamType == null)
+ {
+ addProblem(new UnknownTypeProblem(site, paramString));
+ return null;
+ }
+ else
+ {
+ ParameterDefinition paramDef = new ParameterDefinition(i + "");
+ if (isRest)
+ {
+ paramDef.setRest();
+ }
+ if (hasDefaultValue)
+ {
+ paramDef.setDefaultValue(true);
+ }
+ paramDef.setTypeReference(new
ResolvedReference(resolvedParamType));
+ parsedParams.add(paramDef);
+ }
+ }
+ return parsedParams;
+ }
+
+ private String buildFunctionSignatureString(List<IParameterDefinition>
params, ITypeDefinition returnType)
+ {
+ StringBuilder functionBuilder = new StringBuilder();
+ functionBuilder.append(IASKeywordConstants.FUNCTION);
+ functionBuilder.append("(");
+ for (int i = 0; i < params.size(); i++)
+ {
+ if (i > 0)
+ {
+ functionBuilder.append(", ");
+ }
+ IParameterDefinition paramDef = params.get(i);
+ if (paramDef.isRest())
+ {
+ functionBuilder.append("...");
+ functionBuilder.append(paramDef.getBaseName());
+ }
+ else
+ {
+ ITypeDefinition paramTypeDef = paramDef.resolveType(project);
+ if (paramTypeDef == null)
+ {
+ functionBuilder.append(paramDef.getTypeAsDisplayString());
+ }
+ else
+ {
+ functionBuilder.append(paramTypeDef.getBaseName());
+ }
+ if (paramDef.hasDefaultValue())
+ {
+ functionBuilder.append("=");
+ }
+ }
+ }
+ functionBuilder.append(")");
+ if (returnType != null)
+ {
+ functionBuilder.append(":");
+ functionBuilder.append(returnType.getBaseName());
+ }
+ return functionBuilder.toString();
+ }
/**
* Checks that the value (RHS) is appropriate, given the type of the LHS
@@ -283,7 +552,19 @@ public class MethodBodySemanticChecker
{
// Check the assignment's type logic.
if ( binding.getDefinition() != null )
- checkImplicitConversion(SemanticUtils.getNthChild(iNode, 2),
binding.getDefinition().resolveType(project), null);
+ {
+ IDefinition leftDef = binding.getDefinition();
+ IASNode rightNode = SemanticUtils.getNthChild(iNode, 2);
+
+ ITypeDefinition leftType = leftDef.resolveType(project);
+ if (project.getAllowStrictFunctionTypes() &&
project.getBuiltinType(BuiltinType.FUNCTION).equals(leftType))
+ {
+ IASNode leftNode = SemanticUtils.getNthChild(iNode, 0);
+ checkFunctionTypeMeta(leftNode, rightNode);
+ }
+
+ checkImplicitConversion(rightNode, leftType, null);
+ }
}
/**
@@ -725,21 +1006,24 @@ public class MethodBodySemanticChecker
*/
private void checkFormalsVsActuals(IASNode iNode, FunctionDefinition func,
Vector<? extends Object> actuals)
{
-
// If the call is through a function variable then we don't know much
about it.
// If we get a setter function assume a getter is what was meant
since calling a setter
// directly is not legal and resolving the name for a getter/setter
could
// return either. Code generation does the right thing so changing
this check
// to just return for setters as well.
if ( func instanceof GetterDefinition || func instanceof
SetterDefinition)
+ {
return;
+ }
// Check the formal parameter definitions, and ensure we have
// a corresponding number of actual parameters.
ParameterDefinition[] formals = func.getParameters();
if ( formals == null )
+ {
return;
+ }
boolean last_is_rest = formals.length > 0 && formals[formals.length
- 1].isRest();
@@ -776,7 +1060,36 @@ public class MethodBodySemanticChecker
for ( int i = 0; i < actuals_container.getChildCount() && i <
formals.length; i++ )
{
if ( !formals[i].isRest() )
- checkImplicitConversion( actuals_container.getChild(i),
formals[i].resolveType(project), func );
+ {
+ IASNode actualNode = actuals_container.getChild(i);
+ ParameterDefinition formalParam = formals[i];
+ ITypeDefinition formalParamType =
formalParam.resolveType(project);
+ if (project.getAllowStrictFunctionTypes() &&
project.getBuiltinType(BuiltinType.FUNCTION).equals(formalParamType))
+ {
+ // we can't add metadata directly to parameters, so we
+ // need to find it on the function that contains the
+ // parameter
+ IMetaTag[] functionTypeTags =
func.getMetaTagsByName(IMetaAttributeConstants.ATTRIBUTE_FUNCTION_TYPE);
+ if (functionTypeTags != null)
+ {
+ IMetaTag foundMetaTag = null;
+ for (IMetaTag functionTypeTag : functionTypeTags)
+ {
+ String paramName =
functionTypeTag.getAttributeValue(IMetaAttributeConstants.NAME_FUNCTION_TYPE_PARAM_NAME);
+ if (paramName != null &&
paramName.equals(formalParam.getBaseName()))
+ {
+ foundMetaTag = functionTypeTag;
+ break;
+ }
+ }
+ if (foundMetaTag != null)
+ {
+ checkFunctionTypeMeta(foundMetaTag, iNode,
actualNode);
+ }
+ }
+ }
+ checkImplicitConversion( actualNode, formalParamType, func
);
+ }
}
}
}
diff --git a/compiler/src/test/java/as/ASStrictFunctionTypesMetadataTests.java
b/compiler/src/test/java/as/ASStrictFunctionTypesMetadataTests.java
new file mode 100644
index 000000000..aecf216a9
--- /dev/null
+++ b/compiler/src/test/java/as/ASStrictFunctionTypesMetadataTests.java
@@ -0,0 +1,2583 @@
+/*
+ *
+ * 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 as;
+
+import org.junit.Test;
+
+public class ASStrictFunctionTypesMetadataTests extends ASFeatureTestsBase
+{
+ @Test
+ public void
testWrongParameterType1_assignVariableToVariable_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(returns=\"void\",params=\"String\")]",
+ "var a:Function;",
+
"[RoyaleFunctionType(returns=\"void\",params=\"Number\")]",
+ "var b:Function;",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectErrors(source, false, false, false, options, "Implicit
coercion of a value of type function(Number):void to an unrelated type
function(String):void.\n");
+ }
+
+ @Test
+ public void
testWrongParameterType1_assignVariableToVariable_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(returns=\"void\",params=\"String\")]",
+ "var a:Function;",
+
"[RoyaleFunctionType(returns=\"void\",params=\"Number\")]",
+ "var b:Function;",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testWrongParameterType2_assignVariableToVariable_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number\")]",
+ "var a:Function;",
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Boolean\")]",
+ "var b:Function;",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectErrors(source, false, false, false, options, "Implicit
coercion of a value of type function(String, Boolean):void to an unrelated type
function(String, Number):void.\n");
+ }
+
+ @Test
+ public void
testWrongParameterType2_assignVariableToVariable_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number\")]",
+ "var a:Function;",
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Boolean\")]",
+ "var b:Function;",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testCorrectParameterTypes_assignVariableToVariable_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number,Boolean\")]",
+ "var a:Function;",
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number,Boolean\")]",
+ "var b:Function;",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testCorrectParameterTypes_assignVariableToVariable_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number,Boolean\")]",
+ "var a:Function;",
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number,Boolean\")]",
+ "var b:Function;",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testRestParameterInsteadOfCorrectParameterTypes1_assignVariableToVariable_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number,Boolean\")]",
+ "var a:Function;",
+
"[RoyaleFunctionType(returns=\"void\",params=\"...Array\")]",
+ "var b:Function;",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectNoErrors(source, false,false,false, options);
+ }
+
+ @Test
+ public void
testRestParameterInsteadOfCorrectParameterTypes1_assignVariableToVariable_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number,Boolean\")]",
+ "var a:Function;",
+
"[RoyaleFunctionType(returns=\"void\",params=\"...Array\")]",
+ "var b:Function;",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false,false,false, options);
+ }
+
+ @Test
+ public void
testRestParameterInsteadOfCorrectParameterTypes2_assignVariableToVariable_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number,Boolean\")]",
+ "var a:Function;",
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,...Array\")]",
+ "var b:Function;",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectNoErrors(source, false,false,false, options);
+ }
+
+ @Test
+ public void
testRestParameterInsteadOfCorrectParameterTypes2_assignVariableToVariable_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number,Boolean\")]",
+ "var a:Function;",
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,...Array\")]",
+ "var b:Function;",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false,false,false, options);
+ }
+
+ @Test
+ public void
testRestParameterInsteadOfCorrectParameterTypes3_assignVariableToVariable_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number,Boolean\")]",
+ "var a:Function;",
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number,...Array\")]",
+ "var b:Function;",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectNoErrors(source, false,false,false, options);
+ }
+
+ @Test
+ public void
testRestParameterInsteadOfCorrectParameterTypes3_assignVariableToVariable_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number,Boolean\")]",
+ "var a:Function;",
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number,...Array\")]",
+ "var b:Function;",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false,false,false, options);
+ }
+
+ @Test
+ public void
testRestParameterInsteadOfCorrectParameterTypes4_assignVariableToVariable_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number,Boolean\")]",
+ "var a:Function;",
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number,Boolean,...Array\")]",
+ "var b:Function;",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectNoErrors(source, false,false,false, options);
+ }
+
+ @Test
+ public void
testRestParameterInsteadOfCorrectParameterTypes4_assignVariableToVariable_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number,Boolean\")]",
+ "var a:Function;",
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number,Boolean,...Array\")]",
+ "var b:Function;",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false,false,false, options);
+ }
+
+ @Test
+ public void
testWrongReturnType_assignVariableToVariable_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+ "[RoyaleFunctionType(returns=\"String\",params=\"\")]",
+ "var a:Function;",
+ "[RoyaleFunctionType(returns=\"Number\",params=\"\")]",
+ "var b:Function;",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectErrors(source, false, false, false, options, "Implicit
coercion of a value of type function():Number to an unrelated type
function():String.\n");
+ }
+
+ @Test
+ public void
testWrongReturnType_assignVariableToVariable_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+ "[RoyaleFunctionType(returns=\"String\",params=\"\")]",
+ "var a:Function;",
+ "[RoyaleFunctionType(returns=\"Number\",params=\"\")]",
+ "var b:Function;",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testCorrectReturnType_assignVariableToVariable_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+ "[RoyaleFunctionType(returns=\"String\",params=\"\")]",
+ "var a:Function;",
+ "[RoyaleFunctionType(returns=\"String\",params=\"\")]",
+ "var b:Function;",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testCorrectReturnType_assignVariableToVariable_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+ "[RoyaleFunctionType(returns=\"String\",params=\"\")]",
+ "var a:Function;",
+ "[RoyaleFunctionType(returns=\"String\",params=\"\")]",
+ "var b:Function;",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testIgnoreReturnTypeForVoid_assignVariableToVariable_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+ "[RoyaleFunctionType(returns=\"void\",params=\"\")]",
+ "var a:Function;",
+ "[RoyaleFunctionType(returns=\"String\",params=\"\")]",
+ "var b:Function;",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testIgnoreReturnTypeForVoid_assignVariableToVariable_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+ "[RoyaleFunctionType(returns=\"void\",params=\"\")]",
+ "var a:Function;",
+ "[RoyaleFunctionType(returns=\"String\",params=\"\")]",
+ "var b:Function;",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testAssignStrictTypeToRegular_assignVariableToVariable_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+ "var a:Function;",
+ "[RoyaleFunctionType(returns=\"String\",params=\"\")]",
+ "var b:Function;",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testAssignStrictTypeToRegular_assignVariableToVariable_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+ "var a:Function;",
+ "[RoyaleFunctionType(returns=\"String\",params=\"\")]",
+ "var b:Function;",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testAssignRegularTypeToStrict_assignVariableToVariable_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(returns=\"void\",params=\"String\")]",
+ "var a:Function;",
+ "var b:Function;",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectErrors(source, false, false, false, options, "Implicit
coercion of a value of type Function to an unrelated type
function(String):void.\n");
+ }
+
+ @Test
+ public void
testAssignRegularTypeToStrict_assignVariableToVariable_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(returns=\"void\",params=\"String\")]",
+ "var a:Function;",
+ "var b:Function;",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testWrongParameterType1_assignFunctionToVariable_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(returns=\"void\",params=\"String\")]",
+ "var a:Function;",
+ "function b(x:Number):void {}",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectErrors(source, false, false, false, options, "Implicit
coercion of a value of type function(Number):void to an unrelated type
function(String):void.\n");
+ }
+
+ @Test
+ public void
testWrongParameterType1_assignFunctionToVariable_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(returns=\"void\",params=\"String\")]",
+ "var a:Function;",
+ "function b(x:Number):void {}",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testWrongParameterType2_assignFunctionToVariable_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number\")]",
+ "var a:Function;",
+ "function b(x:String, y:Boolean):void {}",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectErrors(source, false, false, false, options, "Implicit
coercion of a value of type function(String, Boolean):void to an unrelated type
function(String, Number):void.\n");
+ }
+
+ @Test
+ public void
testWrongParameterType2_assignFunctionToVariable_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number\")]",
+ "var a:Function;",
+ "function b(x:String, y:Boolean):void {}",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testCorrectParameterTypes_assignFunctionToVariable_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number,Boolean\")]",
+ "var a:Function;",
+ "function b(x:String, y:Number, z:Boolean):void {}",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testCorrectParameterTypes_assignFunctionToVariable_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number,Boolean\")]",
+ "var a:Function;",
+ "function b(x:String, y:Number, z:Boolean):void {}",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testRestParameterInsteadOfCorrectParameterTypes1_assignFunctionToVariable_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number,Boolean\")]",
+ "var a:Function;",
+ "function b(...rest):void {}",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectNoErrors(source, false,false,false, options);
+ }
+
+ @Test
+ public void
testRestParameterInsteadOfCorrectParameterTypes1_assignFunctionToVariable_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number,Boolean\")]",
+ "var a:Function;",
+ "function b(...rest):void {}",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false,false,false, options);
+ }
+
+ @Test
+ public void
testRestParameterInsteadOfCorrectParameterTypes2_assignFunctionToVariable_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number,Boolean\")]",
+ "var a:Function;",
+ "function b(x:String, ...rest):void {}",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectNoErrors(source, false,false,false, options);
+ }
+
+ @Test
+ public void
testRestParameterInsteadOfCorrectParameterTypes2_assignFunctionToVariable_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number,Boolean\")]",
+ "var a:Function;",
+ "function b(x:String, ...rest):void {}",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false,false,false, options);
+ }
+
+ @Test
+ public void
testRestParameterInsteadOfCorrectParameterTypes3_assignFunctionToVariable_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number,Boolean\")]",
+ "var a:Function;",
+ "function b(x:String, y:Number, ...rest):void {}",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectNoErrors(source, false,false,false, options);
+ }
+
+ @Test
+ public void
testRestParameterInsteadOfCorrectParameterTypes3_assignFunctionToVariable_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number,Boolean\")]",
+ "var a:Function;",
+ "function b(x:String, y:Number, ...rest):void {}",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false,false,false, options);
+ }
+
+ @Test
+ public void
testRestParameterInsteadOfCorrectParameterTypes4_assignFunctionToVariable_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number,Boolean\")]",
+ "var a:Function;",
+ "function b(x:String, y:Number, z:Boolean,
...rest):void {}",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectNoErrors(source, false,false,false, options);
+ }
+
+ @Test
+ public void
testRestParameterInsteadOfCorrectParameterTypes4_assignFunctionToVariable_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number,Boolean\")]",
+ "var a:Function;",
+ "function b(x:String, y:Number, z:Boolean,
...rest):void {}",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false,false,false, options);
+ }
+
+ @Test
+ public void
testWrongReturnType_assignFunctionToVariable_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+ "[RoyaleFunctionType(returns=\"String\",params=\"\")]",
+ "var a:Function;",
+ "function b():Number {return 0;}",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectErrors(source, false, false, false, options, "Implicit
coercion of a value of type function():Number to an unrelated type
function():String.\n");
+ }
+
+ @Test
+ public void
testWrongReturnType_assignFunctionToVariable_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+ "[RoyaleFunctionType(returns=\"String\",params=\"\")]",
+ "var a:Function;",
+ "function b():Number {return 0;}",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testCorrectReturnType_assignFunctionToVariable_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+ "[RoyaleFunctionType(returns=\"String\",params=\"\")]",
+ "var a:Function;",
+ "function b():String {return null;}",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testCorrectReturnType_assignFunctionToVariable_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+ "[RoyaleFunctionType(returns=\"String\",params=\"\")]",
+ "var a:Function;",
+ "function b():String {return null;}",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testIgnoreReturnTypeForVoid_assignFunctionToVariable_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+ "[RoyaleFunctionType(returns=\"void\",params=\"\")]",
+ "var a:Function;",
+ "function b():String {return null;}",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testIgnoreReturnTypeForVoid_assignFunctionToVariable_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+ "[RoyaleFunctionType(returns=\"void\",params=\"\")]",
+ "var a:Function;",
+ "function b():String {return null;}",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testAssignFunctionToVariable_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+ "var a:Function;",
+ "function b(x:String):Number { return 0; }",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testAssignFunctionToVariable_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+ "var a:Function;",
+ "function b(x:String):Number { return 0; }",
+ "a = b;"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testWrongParameterType1_passVariableToParameter_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"void\",params=\"String\")]",
+ "function a(x:Function):void {}",
+
"[RoyaleFunctionType(returns=\"void\",params=\"Number\")]",
+ "var b:Function;",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectErrors(source, false, false, false, options, "Implicit
coercion of a value of type function(Number):void to an unrelated type
function(String):void.\n");
+ }
+
+ @Test
+ public void
testWrongParameterType1_passVariableToParameter_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"void\",params=\"String\")]",
+ "function a(x:Function):void {}",
+
"[RoyaleFunctionType(returns=\"void\",params=\"Number\")]",
+ "var b:Function;",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testWrongParameterType2_passVariableToParameter_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"y\",returns=\"void\",params=\"String,Number\")]",
+ "function a(x:String, y:Function):void {}",
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Boolean\")]",
+ "var b:Function;",
+ "a(\"hi\", b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectErrors(source, false, false, false, options, "Implicit
coercion of a value of type function(String, Boolean):void to an unrelated type
function(String, Number):void.\n");
+ }
+
+ @Test
+ public void
testWrongParameterType2_passVariableToParameter_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"y\",returns=\"void\",params=\"String,Number\")]",
+ "function a(x:String, y:Function):void {}",
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Boolean\")]",
+ "var b:Function;",
+ "a(\"hi\", b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testCorrectParameterTypes_passVariableToParameter_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"void\",params=\"String,Number,Boolean\")]",
+ "function a(x:Function):void {}",
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number,Boolean\")]",
+ "var b:Function;",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testCorrectParameterTypes_passVariableToParameter_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"void\",params=\"String,Number,Boolean\")]",
+ "function a(x:Function):void {}",
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number,Boolean\")]",
+ "var b:Function;",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testRestParameterInsteadOfCorrectParameterTypes1_passVariableToParameter_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"void\",params=\"String,Number,Boolean\")]",
+ "function a(x:Function):void {}",
+
"[RoyaleFunctionType(returns=\"void\",params=\"...Array\")]",
+ "var b:Function;",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectNoErrors(source, false,false,false, options);
+ }
+
+ @Test
+ public void
testRestParameterInsteadOfCorrectParameterTypes1_passVariableToParameter_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"void\",params=\"String,Number,Boolean\")]",
+ "function a(x:Function):void {}",
+
"[RoyaleFunctionType(returns=\"void\",params=\"...Array\")]",
+ "var b:Function;",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false,false,false, options);
+ }
+
+ @Test
+ public void
testRestParameterInsteadOfCorrectParameterTypes2_passVariableToParameter_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"void\",params=\"String,Number,Boolean\")]",
+ "function a(x:Function):void {}",
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,...Array\")]",
+ "var b:Function;",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectNoErrors(source, false,false,false, options);
+ }
+
+ @Test
+ public void
testRestParameterInsteadOfCorrectParameterTypes2_passVariableToParameter_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"void\",params=\"String,Number,Boolean\")]",
+ "function a(x:Function):void {}",
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,...Array\")]",
+ "var b:Function;",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false,false,false, options);
+ }
+
+ @Test
+ public void
testRestParameterInsteadOfCorrectParameterTypes3_passVariableToParameter_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"void\",params=\"String,Number,Boolean\")]",
+ "function a(x:Function):void {}",
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number,...Array\")]",
+ "var b:Function;",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectNoErrors(source, false,false,false, options);
+ }
+
+ @Test
+ public void
testRestParameterInsteadOfCorrectParameterTypes3_passVariableToParameter_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"void\",params=\"String,Number,Boolean\")]",
+ "function a(x:Function):void {}",
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number,...Array\")]",
+ "var b:Function;",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false,false,false, options);
+ }
+
+ @Test
+ public void
testRestParameterInsteadOfCorrectParameterTypes4_passVariableToParameter_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"yx\",returns=\"void\",params=\"String,Number,Boolean\")]",
+ "function a(x:Function):void {}",
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number,Boolean,...Array\")]",
+ "var b:Function;",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectNoErrors(source, false,false,false, options);
+ }
+
+ @Test
+ public void
testRestParameterInsteadOfCorrectParameterTypes4_passVariableToParameter_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"yx\",returns=\"void\",params=\"String,Number,Boolean\")]",
+ "function a(x:Function):void {}",
+
"[RoyaleFunctionType(returns=\"void\",params=\"String,Number,Boolean,...Array\")]",
+ "var b:Function;",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false,false,false, options);
+ }
+
+ @Test
+ public void
testWrongReturnType_passVariableToParameter_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"String\",params=\"\")]",
+ "function a(x:Function):void {}",
+ "[RoyaleFunctionType(returns=\"Number\",params=\"\")]",
+ "var b:Function;",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectErrors(source, false, false, false, options, "Implicit
coercion of a value of type function():Number to an unrelated type
function():String.\n");
+ }
+
+ @Test
+ public void
testWrongReturnType_passVariableToParameter_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"String\",params=\"\")]",
+ "function a(x:Function):void {}",
+ "[RoyaleFunctionType(returns=\"Number\",params=\"\")]",
+ "var b:Function;",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testCorrectReturnType_passVariableToParameter_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"String\",params=\"\")]",
+ "function a(x:Function):void {}",
+ "[RoyaleFunctionType(returns=\"String\",params=\"\")]",
+ "var b:Function;",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testCorrectReturnType_passVariableToParameter_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"String\",params=\"\")]",
+ "function a(x:Function):void {}",
+ "[RoyaleFunctionType(returns=\"String\",params=\"\")]",
+ "var b:Function;",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testIgnoreReturnTypeForVoid_passVariableToParameter_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"void\",params=\"\")]",
+ "function a(x:Function):void {}",
+ "[RoyaleFunctionType(returns=\"String\",params=\"\")]",
+ "var b:Function;",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testIgnoreReturnTypeForVoid_passVariableToParameter_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"void\",params=\"\")]",
+ "function a(x:Function):void {}",
+ "[RoyaleFunctionType(returns=\"String\",params=\"\")]",
+ "var b:Function;",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testAssignStrictTypeToRegular_passVariableToParameter_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+ "function a(x:Function):void {}",
+ "[RoyaleFunctionType(returns=\"String\",params=\"\")]",
+ "var b:Function;",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testAssignStrictTypeToRegular_passVariableToParameter_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+ "function a(x:Function):void {}",
+ "[RoyaleFunctionType(returns=\"String\",params=\"\")]",
+ "var b:Function;",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testAssignRegularTypeToStrict_passVariableToParameter_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"void\",params=\"String\")]",
+ "function a(x:Function):void {}",
+ "var b:Function;",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectErrors(source, false, false, false, options, "Implicit
coercion of a value of type Function to an unrelated type
function(String):void.\n");
+ }
+
+ @Test
+ public void
testAssignRegularTypeToStrict_passVariableToParameter_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"void\",params=\"String\")]",
+ "function a(x:Function):void {}",
+ "var b:Function;",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testWrongParameterType1_passFunctionToParameter_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"void\",params=\"String\")]",
+ "function a(x:Function):void {}",
+ "function b(x:Number):void {}",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectErrors(source, false, false, false, options, "Implicit
coercion of a value of type function(Number):void to an unrelated type
function(String):void.\n");
+ }
+
+ @Test
+ public void
testWrongParameterType1_passFunctionToParameter_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"void\",params=\"String\")]",
+ "function a(x:Function):void {}",
+ "function b(x:Number):void {}",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testWrongParameterType2_passFunctionToParameter_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"void\",params=\"String,Number\")]",
+ "function a(x:Function):void {}",
+ "function b(x:String, y:Boolean):void {}",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectErrors(source, false, false, false, options, "Implicit
coercion of a value of type function(String, Boolean):void to an unrelated type
function(String, Number):void.\n");
+ }
+
+ @Test
+ public void
testWrongParameterType2_passFunctionToParameter_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"void\",params=\"String,Number\")]",
+ "function a(x:Function):void {}",
+ "function b(x:String, y:Boolean):void {}",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testCorrectParameterTypes_passFunctionToParameter_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"void\",params=\"String,Number,Boolean\")]",
+ "function a(x:Function):void {}",
+ "function b(x:String, y:Number, z:Boolean):void {}",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testCorrectParameterTypes_passFunctionToParameter_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"void\",params=\"String,Number,Boolean\")]",
+ "function a(x:Function):void {}",
+ "function b(x:String, y:Number, z:Boolean):void {}",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testRestParameterInsteadOfCorrectParameterTypes1_passFunctionToParameter_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"void\",params=\"String,Number,Boolean\")]",
+ "function a(x:Function):void {}",
+ "function b(...rest):void {}",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectNoErrors(source, false,false,false, options);
+ }
+
+ @Test
+ public void
testRestParameterInsteadOfCorrectParameterTypes1_passFunctionToParameter_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"void\",params=\"String,Number,Boolean\")]",
+ "function a(x:Function):void {}",
+ "function b(...rest):void {}",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false,false,false, options);
+ }
+
+ @Test
+ public void
testRestParameterInsteadOfCorrectParameterTypes2_passFunctionToParameter_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"void\",params=\"String,Number,Boolean\")]",
+ "function a(x:Function):void {}",
+ "function b(x:String, ...rest):void {}",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectNoErrors(source, false,false,false, options);
+ }
+
+ @Test
+ public void
testRestParameterInsteadOfCorrectParameterTypes2_passFunctionToParameter_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"void\",params=\"String,Number,Boolean\")]",
+ "function a(x:Function):void {}",
+ "function b(x:String, ...rest):void {}",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false,false,false, options);
+ }
+
+ @Test
+ public void
testRestParameterInsteadOfCorrectParameterTypes3_passFunctionToParameter_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"void\",params=\"String,Number,Boolean\")]",
+ "function a(x:Function):void {}",
+ "function b(x:String, y:Number, ...rest):void {}",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectNoErrors(source, false,false,false, options);
+ }
+
+ @Test
+ public void
testRestParameterInsteadOfCorrectParameterTypes3_passFunctionToParameter_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"void\",params=\"String,Number,Boolean\")]",
+ "function a(x:Function):void {}",
+ "function b(x:String, y:Number, ...rest):void {}",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false,false,false, options);
+ }
+
+ @Test
+ public void
testRestParameterInsteadOfCorrectParameterTypes4_passFunctionToParameter_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"void\",params=\"String,Number,Boolean\")]",
+ "function a(x:Function):void {}",
+ "function b(x:String, y:Number, z:Boolean,
...rest):void {}",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectNoErrors(source, false,false,false, options);
+ }
+
+ @Test
+ public void
testRestParameterInsteadOfCorrectParameterTypes4_passFunctionToParameter_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"void\",params=\"String,Number,Boolean\")]",
+ "function a(x:Function):void {}",
+ "function b(x:String, y:Number, z:Boolean,
...rest):void {}",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false,false,false, options);
+ }
+
+ @Test
+ public void
testWrongReturnType_passFunctionToParameter_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"String\",params=\"\")]",
+ "function a(x:Function):void {}",
+ "function b():Number { return 0; }",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectErrors(source, false, false, false, options, "Implicit
coercion of a value of type function():Number to an unrelated type
function():String.\n");
+ }
+
+ @Test
+ public void
testWrongReturnType_passFunctionToParameter_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"String\",params=\"\")]",
+ "function a(x:Function):void {}",
+ "function b():Number { return 0; }",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testCorrectReturnType_passFunctionToParameter_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"String\",params=\"\")]",
+ "function a(x:Function):void {}",
+ "function b():String { return null; }",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testCorrectReturnType_passFunctionToParameter_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"String\",params=\"\")]",
+ "function a(x:Function):void {}",
+ "function b():String { return null; }",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testIgnoreReturnTypeForVoid_passFunctionToParameter_withAllowStrictFunctionTypesEnabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"void\",params=\"\")]",
+ "function a(x:Function):void {}",
+ "function b():String { return null; }",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=true"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+
+ @Test
+ public void
testIgnoreReturnTypeForVoid_passFunctionToParameter_withAllowStrictFunctionTypesDisabled()
+ {
+ String[] imports = new String[]
+ {
+ };
+ String[] declarations = new String[]
+ {
+ };
+ String[] testCode = new String[]
+ {
+ };
+ String[] extra = new String[]
+ {
+
"[RoyaleFunctionType(paramName=\"x\",returns=\"void\",params=\"\")]",
+ "function a(x:Function):void {}",
+ "function b():String { return null; }",
+ "a(b);"
+ };
+ String source = getAS(imports, declarations, testCode, extra);
+
+ String[] options = new String[]
+ {
+ "-allow-strict-function-types=false"
+ };
+ compileAndExpectNoErrors(source, false, false, false, options);
+ }
+}
\ No newline at end of file