@@ -1465,6 +1465,48 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
1465
1465
new VoidTypeDeclarationBuilder (const VoidType (), this , charOffset));
1466
1466
}
1467
1467
1468
+ void _checkBadFunctionParameter (List <TypeVariableBuilder > typeVariables) {
1469
+ if (typeVariables == null || typeVariables.isEmpty) {
1470
+ return ;
1471
+ }
1472
+
1473
+ for (TypeVariableBuilder type in typeVariables) {
1474
+ if (type.name == "Function" ) {
1475
+ addProblem (messageFunctionAsTypeParameter, type.charOffset,
1476
+ type.name.length, type.fileUri);
1477
+ }
1478
+ }
1479
+ }
1480
+
1481
+ void _checkBadFunctionDeclUse (String className, TypeParameterScopeKind kind,
1482
+ int charOffset) {
1483
+ String decType;
1484
+ switch (kind) {
1485
+ case TypeParameterScopeKind .classDeclaration:
1486
+ decType = "class" ;
1487
+ break ;
1488
+ case TypeParameterScopeKind .mixinDeclaration:
1489
+ decType = "mixin" ;
1490
+ break ;
1491
+ case TypeParameterScopeKind .extensionDeclaration:
1492
+ decType = "extension" ;
1493
+ break ;
1494
+ default :
1495
+ break ;
1496
+ }
1497
+ if (className != "Function" ) {
1498
+ return ;
1499
+ }
1500
+ if (decType == "class" && importUri.scheme == "dart" ) {
1501
+ // Allow declaration of class Function in the sdk.
1502
+ return ;
1503
+ }
1504
+ if (decType != null ) {
1505
+ addProblem (templateFunctionUsedAsDec.withArguments (decType), charOffset,
1506
+ className? .length, fileUri);
1507
+ }
1508
+ }
1509
+
1468
1510
/// Add a problem that might not be reported immediately.
1469
1511
///
1470
1512
/// Problems will be issued after source information has been added.
@@ -1574,6 +1616,8 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
1574
1616
int nameOffset,
1575
1617
int endOffset,
1576
1618
int supertypeOffset) {
1619
+ _checkBadFunctionDeclUse (className, kind, nameOffset);
1620
+ _checkBadFunctionParameter (typeVariables);
1577
1621
// Nested declaration began in `OutlineBuilder.beginClassDeclaration`.
1578
1622
TypeParameterScopeBuilder declaration =
1579
1623
endNestedDeclaration (kind, className)
@@ -1806,6 +1850,9 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
1806
1850
int startOffset,
1807
1851
int nameOffset,
1808
1852
int endOffset) {
1853
+ _checkBadFunctionDeclUse (
1854
+ extensionName, TypeParameterScopeKind .extensionDeclaration, nameOffset);
1855
+ _checkBadFunctionParameter (typeVariables);
1809
1856
// Nested declaration began in `OutlineBuilder.beginExtensionDeclaration`.
1810
1857
TypeParameterScopeBuilder declaration = endNestedDeclaration (
1811
1858
TypeParameterScopeKind .extensionDeclaration, extensionName)
@@ -1837,7 +1884,6 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
1837
1884
nameOffset,
1838
1885
endOffset,
1839
1886
referenceFrom);
1840
-
1841
1887
constructorReferences.clear ();
1842
1888
Map <String , TypeVariableBuilder > typeVariablesByName =
1843
1889
checkTypeVariables (typeVariables, extensionBuilder);
0 commit comments