Skip to content

Can't read TreeNode.location from patch files #31579

Open
@sigmundch

Description

@sigmundch

Many nodes contain a fileoffset but no file uri. TreeNode.location searches up the tree to find the first node with a file uri (typically a member, class, or library). How does this work when using patch files?
It appears as if we use the tree node from the original library for these elements, and the body and annotations from the patch file are attached.

This is causing problems in the lookup of the location of these nodes. The offset corresponds to the patch file, but we try to look for it in the original library source instead. As a result we commonly hit "out-of-range" errors when calling TreeNode.location.

Here is a repro:

You'll see this error:

The compiler crashed: RangeError (offset): Invalid value: Not in range 0..566, inclusive: 975
#0      RangeError.checkValueInInterval (dart:core/errors.dart:267)
#1      Source.getLocation (package:kernel/ast.dart:5693:16)
#2      Program.getLocation (package:kernel/ast.dart:5487:31)
#3      _getLocationInProgram (package:kernel/ast.dart:5808:20)
#4      Procedure._getLocationInEnclosingFile (package:kernel/ast.dart:1563:12)
#5      TreeNode._getLocationInEnclosingFile (package:kernel/ast.dart:169:20)
#6      TreeNode.location (package:kernel/ast.dart:165:12)
#7      computeSourceSpanFromTreeNode (sdk/pkg/compiler/lib/src/kernel/element_map.dart:491:18)
#8      KernelToElementMapBaseMixin.getConstantValue (sdk/pkg/compiler/lib/src/kernel/element_map_mixins.dart:330:9)
#9      KernelToElementMapBaseMixin.getMetadata.<anonymous closure> (pkg/compiler/lib/src/kernel/element_map_mixins.dart:343:20)
#10     List.forEach (dart:core-patch/dart:core/array.dart:79)
#11     KernelToElementMapBaseMixin.getMetadata (sdk/pkg/compiler/lib/src/kernel/element_map_mixins.dart:342:17)
...

The failure occurs when looking for the location of the @patch annotation in printToConsole.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions