@@ -2266,22 +2266,37 @@ void main() {
22662266 theOnlyThingInTheLibrary;
22672267 Constructor aNonDefaultConstructor,
22682268 defaultConstructor,
2269- aConstructorShadowed;
2269+ aConstructorShadowed,
2270+ anotherName,
2271+ anotherConstructor,
2272+ factoryConstructorThingsDefault;
22702273 Class Apple ,
22712274 BaseClass ,
22722275 baseForDocComments,
22732276 ExtraSpecialList ,
2277+ FactoryConstructorThings ,
22742278 string,
22752279 metaUseResult;
2276- Method doAwesomeStuff, anotherMethod;
2280+ Method doAwesomeStuff, anotherMethod, aMethod ;
22772281 // ignore: unused_local_variable
22782282 Operator bracketOperator, bracketOperatorOtherClass;
2279- Parameter doAwesomeStuffParam;
2283+ Parameter doAwesomeStuffParam,
2284+ aName,
2285+ anotherNameParameter,
2286+ anotherDifferentName,
2287+ differentName,
2288+ redHerring,
2289+ yetAnotherName,
2290+ somethingShadowyParameter;
22802291 Field forInheriting,
22812292 action,
22822293 initializeMe,
22832294 somethingShadowy,
2284- aConstructorShadowedField;
2295+ aConstructorShadowedField,
2296+ aNameField,
2297+ anotherNameField,
2298+ yetAnotherNameField,
2299+ initViaFieldFormal;
22852300
22862301 setUpAll (() async {
22872302 mylibpub = packageGraph.allLibraries.values
@@ -2309,6 +2324,8 @@ void main() {
23092324 (c) => c.name == 'BaseForDocComments.aNonDefaultConstructor' );
23102325 defaultConstructor = baseForDocComments.constructors
23112326 .firstWhere ((c) => c.name == 'BaseForDocComments' );
2327+ somethingShadowyParameter = defaultConstructor.allParameters
2328+ .firstWhere ((p) => p.name == 'somethingShadowy' );
23122329 initializeMe = baseForDocComments.allFields
23132330 .firstWhere ((f) => f.name == 'initializeMe' );
23142331 somethingShadowy = baseForDocComments.allFields
@@ -2361,6 +2378,106 @@ void main() {
23612378 (c) => c.name == 'BaseForDocComments.aConstructorShadowed' );
23622379 aConstructorShadowedField = baseForDocComments.allFields
23632380 .firstWhere ((f) => f.name == 'aConstructorShadowed' );
2381+
2382+ FactoryConstructorThings = fakeLibrary.classes
2383+ .firstWhere ((c) => c.name == 'FactoryConstructorThings' );
2384+ anotherName = FactoryConstructorThings .constructors.firstWhere (
2385+ (c) => c.name == 'FactoryConstructorThings.anotherName' );
2386+ anotherConstructor = FactoryConstructorThings .constructors.firstWhere (
2387+ (c) => c.name == 'FactoryConstructorThings.anotherConstructor' );
2388+ factoryConstructorThingsDefault = FactoryConstructorThings .constructors
2389+ .firstWhere ((c) => c.name == 'FactoryConstructorThings' );
2390+
2391+ aName = anotherName.allParameters.firstWhere ((p) => p.name == 'aName' );
2392+ anotherNameParameter = anotherName.allParameters
2393+ .firstWhere ((p) => p.name == 'anotherName' );
2394+ anotherDifferentName = anotherName.allParameters
2395+ .firstWhere ((p) => p.name == 'anotherDifferentName' );
2396+ differentName = anotherName.allParameters
2397+ .firstWhere ((p) => p.name == 'differentName' );
2398+ redHerring = anotherConstructor.allParameters
2399+ .firstWhere ((p) => p.name == 'redHerring' );
2400+
2401+ aNameField = FactoryConstructorThings .allFields
2402+ .firstWhere ((f) => f.name == 'aName' );
2403+ anotherNameField = FactoryConstructorThings .allFields
2404+ .firstWhere ((f) => f.name == 'anotherName' );
2405+ yetAnotherNameField = FactoryConstructorThings .allFields
2406+ .firstWhere ((f) => f.name == 'yetAnotherName' );
2407+ initViaFieldFormal = FactoryConstructorThings .allFields
2408+ .firstWhere ((f) => f.name == 'initViaFieldFormal' );
2409+
2410+ aMethod = FactoryConstructorThings .instanceMethods
2411+ .firstWhere ((m) => m.name == 'aMethod' );
2412+ yetAnotherName =
2413+ aMethod.allParameters.firstWhere ((p) => p.name == 'yetAnotherName' );
2414+ });
2415+
2416+ group ('Parameter references work properly' , () {
2417+ test ('in class scope overridden by fields' , () {
2418+ expect (bothLookup (FactoryConstructorThings , 'aName' ),
2419+ equals (MatchingLinkResult (aNameField)));
2420+ expect (bothLookup (FactoryConstructorThings , 'anotherName' ),
2421+ equals (MatchingLinkResult (anotherNameField)));
2422+ expect (bothLookup (FactoryConstructorThings , 'yetAnotherName' ),
2423+ equals (MatchingLinkResult (yetAnotherNameField)));
2424+ expect (bothLookup (FactoryConstructorThings , 'initViaFieldFormal' ),
2425+ equals (MatchingLinkResult (initViaFieldFormal)));
2426+ expect (bothLookup (FactoryConstructorThings , 'redHerring' ),
2427+ equals (MatchingLinkResult (redHerring)));
2428+ });
2429+
2430+ test ('in class scope overridden by constructors when specified' , () {
2431+ expect (
2432+ bothLookup (FactoryConstructorThings ,
2433+ 'new FactoryConstructorThings.anotherName' ),
2434+ equals (MatchingLinkResult (anotherName)));
2435+ });
2436+
2437+ test (
2438+ 'in default constructor scope referring to a field formal parameter' ,
2439+ () {
2440+ expect (
2441+ newLookup (factoryConstructorThingsDefault, 'initViaFieldFormal' ),
2442+ equals (MatchingLinkResult (initViaFieldFormal)));
2443+ });
2444+
2445+ test ('in factory constructor scope referring to parameters' , () {
2446+ expect (newLookup (anotherName, 'aName' ),
2447+ equals (MatchingLinkResult (aName)));
2448+ expect (bothLookup (anotherName, 'anotherName' ),
2449+ equals (MatchingLinkResult (anotherNameParameter)));
2450+ expect (bothLookup (anotherName, 'anotherDifferentName' ),
2451+ equals (MatchingLinkResult (anotherDifferentName)));
2452+ expect (bothLookup (anotherName, 'differentName' ),
2453+ equals (MatchingLinkResult (differentName)));
2454+ expect (bothLookup (anotherName, 'redHerring' ),
2455+ equals (MatchingLinkResult (redHerring)));
2456+ });
2457+
2458+ test ('in factory constructor scope referring to constructors' , () {
2459+ // A bare constructor reference is OK because there is no conflict.
2460+ expect (bothLookup (anotherName, 'anotherConstructor' ),
2461+ equals (MatchingLinkResult (anotherConstructor)));
2462+ // A conflicting constructor has to be explicit.
2463+ expect (
2464+ bothLookup (
2465+ anotherName, 'new FactoryConstructorThings.anotherName' ),
2466+ equals (MatchingLinkResult (anotherName)));
2467+ });
2468+
2469+ test ('in method scope referring to parameters and variables' , () {
2470+ expect (bothLookup (aMethod, 'yetAnotherName' ),
2471+ equals (MatchingLinkResult (yetAnotherName)));
2472+ expect (bothLookup (aMethod, 'FactoryConstructorThings.yetAnotherName' ),
2473+ equals (MatchingLinkResult (yetAnotherNameField)));
2474+ expect (
2475+ bothLookup (
2476+ aMethod, 'FactoryConstructorThings.anotherName.anotherName' ),
2477+ equals (MatchingLinkResult (anotherNameParameter)));
2478+ expect (bothLookup (aMethod, 'aName' ),
2479+ equals (MatchingLinkResult (aNameField)));
2480+ });
23642481 });
23652482
23662483 test ('Referring to a renamed library directly works' , () {
@@ -2425,11 +2542,17 @@ void main() {
24252542 equals (MatchingLinkResult (defaultConstructor)));
24262543
24272544 // We don't want the parameter on the default constructor, here.
2428- expect (
2429- bothLookup (
2430- baseForDocComments, 'BaseForDocComments. somethingShadowy' ),
2545+ expect (bothLookup (fakeLibrary, 'BaseForDocComments.somethingShadowy' ),
2546+ equals ( MatchingLinkResult (somethingShadowy)));
2547+ expect ( bothLookup ( baseForDocComments, 'somethingShadowy' ),
24312548 equals (MatchingLinkResult (somethingShadowy)));
24322549
2550+ // Allow specific reference if necessary
2551+ expect (
2552+ newLookup (baseForDocComments,
2553+ 'BaseForDocComments.BaseForDocComments.somethingShadowy' ),
2554+ equals (MatchingLinkResult (somethingShadowyParameter)));
2555+
24332556 expect (bothLookup (doAwesomeStuff, 'aNonDefaultConstructor' ),
24342557 equals (MatchingLinkResult (aNonDefaultConstructor)));
24352558
0 commit comments