@@ -279,13 +279,13 @@ class KernelLibraryBuilder extends SourceLibraryBuilder<TypeBuilder, Library> {
279279 List <TypeVariableBuilder > typeVariables,
280280 TypeBuilder supertype,
281281 List <TypeBuilder > interfaces,
282- int startCharOffset ,
283- int charOffset ,
284- int charEndOffset ,
282+ int startOffset ,
283+ int nameOffset ,
284+ int endOffset ,
285285 int supertypeOffset) {
286286 // Nested declaration began in `OutlineBuilder.beginClassDeclaration`.
287- var declaration = endNestedDeclaration (className)
288- ..resolveTypes (typeVariables, this );
287+ DeclarationBuilder < TypeBuilder > declaration =
288+ endNestedDeclaration (className) ..resolveTypes (typeVariables, this );
289289 assert (declaration.parent == libraryDeclaration);
290290 Map <String , MemberBuilder > members = declaration.members;
291291 Map <String , MemberBuilder > constructors = declaration.constructors;
@@ -312,17 +312,20 @@ class KernelLibraryBuilder extends SourceLibraryBuilder<TypeBuilder, Library> {
312312 modifiers,
313313 className,
314314 typeVariables,
315- applyMixins (supertype, startCharOffset, charOffset, charEndOffset ,
316- className, isMixinDeclaration,
315+ applyMixins (supertype, startOffset, nameOffset, endOffset, className ,
316+ isMixinDeclaration,
317317 typeVariables: typeVariables),
318318 interfaces,
319+ // TODO(johnniwinther): Add the `on` clause types of a mixin declaration
320+ // here.
321+ null ,
319322 classScope,
320323 constructorScope,
321324 this ,
322325 new List <ConstructorReferenceBuilder >.from (constructorReferences),
323- startCharOffset ,
324- charOffset ,
325- charEndOffset ,
326+ startOffset ,
327+ nameOffset ,
328+ endOffset ,
326329 isMixinDeclaration: isMixinDeclaration);
327330 loader.target.metadataCollector
328331 ? .setDocumentationComment (cls.target, documentationComment);
@@ -355,7 +358,7 @@ class KernelLibraryBuilder extends SourceLibraryBuilder<TypeBuilder, Library> {
355358 members.forEach (setParentAndCheckConflicts);
356359 constructors.forEach (setParentAndCheckConflicts);
357360 setters.forEach (setParentAndCheckConflicts);
358- addBuilder (className, cls, charOffset );
361+ addBuilder (className, cls, nameOffset );
359362 }
360363
361364 Map <String , TypeVariableBuilder > checkTypeVariables (
@@ -389,6 +392,91 @@ class KernelLibraryBuilder extends SourceLibraryBuilder<TypeBuilder, Library> {
389392 return typeVariablesByName;
390393 }
391394
395+ @override
396+ void addExtensionDeclaration (
397+ String documentationComment,
398+ List <MetadataBuilder > metadata,
399+ int modifiers,
400+ String extensionName,
401+ List <TypeVariableBuilder > typeVariables,
402+ TypeBuilder type,
403+ int startOffset,
404+ int nameOffset,
405+ int endOffset) {
406+ // Nested declaration began in `OutlineBuilder.beginExtensionDeclaration`.
407+ DeclarationBuilder <TypeBuilder > declaration =
408+ endNestedDeclaration (extensionName)..resolveTypes (typeVariables, this );
409+ assert (declaration.parent == libraryDeclaration);
410+ Map <String , MemberBuilder > members = declaration.members;
411+ Map <String , MemberBuilder > constructors = declaration.constructors;
412+ Map <String , MemberBuilder > setters = declaration.setters;
413+
414+ Scope classScope = new Scope (members, setters,
415+ scope.withTypeVariables (typeVariables), "extension $extensionName " ,
416+ isModifiable: false );
417+
418+ // When looking up a constructor, we don't consider type variables or the
419+ // library scope.
420+ Scope constructorScope =
421+ new Scope (constructors, null , null , extensionName, isModifiable: false );
422+ bool isMixinDeclaration = false ;
423+ if (modifiers & mixinDeclarationMask != 0 ) {
424+ isMixinDeclaration = true ;
425+ modifiers = (modifiers & ~ mixinDeclarationMask) | abstractMask;
426+ }
427+ if (declaration.hasConstConstructor) {
428+ modifiers | = hasConstConstructorMask;
429+ }
430+ ClassBuilder cls = new SourceClassBuilder (
431+ metadata,
432+ modifiers,
433+ extensionName,
434+ typeVariables,
435+ null , // No explicit supertype.
436+ null , // No implemented interfaces.
437+ [type],
438+ classScope,
439+ constructorScope,
440+ this ,
441+ new List <ConstructorReferenceBuilder >.from (constructorReferences),
442+ startOffset,
443+ nameOffset,
444+ endOffset,
445+ isMixinDeclaration: isMixinDeclaration);
446+ loader.target.metadataCollector
447+ ? .setDocumentationComment (cls.target, documentationComment);
448+
449+ constructorReferences.clear ();
450+ Map <String , TypeVariableBuilder > typeVariablesByName =
451+ checkTypeVariables (typeVariables, cls);
452+ void setParent (String name, MemberBuilder member) {
453+ while (member != null ) {
454+ member.parent = cls;
455+ member = member.next;
456+ }
457+ }
458+
459+ void setParentAndCheckConflicts (String name, MemberBuilder member) {
460+ if (typeVariablesByName != null ) {
461+ TypeVariableBuilder tv = typeVariablesByName[name];
462+ if (tv != null ) {
463+ cls.addProblem (templateConflictsWithTypeVariable.withArguments (name),
464+ member.charOffset, name.length,
465+ context: [
466+ messageConflictsWithTypeVariableCause.withLocation (
467+ tv.fileUri, tv.charOffset, name.length)
468+ ]);
469+ }
470+ }
471+ setParent (name, member);
472+ }
473+
474+ members.forEach (setParentAndCheckConflicts);
475+ constructors.forEach (setParentAndCheckConflicts);
476+ setters.forEach (setParentAndCheckConflicts);
477+ addBuilder (extensionName, cls, nameOffset);
478+ }
479+
392480 TypeBuilder applyMixins (TypeBuilder type, int startCharOffset, int charOffset,
393481 int charEndOffset, String subclassName, bool isMixinDeclaration,
394482 {String documentationComment,
@@ -578,6 +666,7 @@ class KernelLibraryBuilder extends SourceLibraryBuilder<TypeBuilder, Library> {
578666 isNamedMixinApplication
579667 ? interfaces
580668 : isMixinDeclaration ? [supertype, mixin ] : null ,
669+ null , // No `on` clause types.
581670 new Scope (< String , MemberBuilder > {}, < String , MemberBuilder > {},
582671 scope.withTypeVariables (typeVariables),
583672 "mixin $fullname " , isModifiable: false ),
0 commit comments