Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retain location metadata for values in convert.FromTyped #1523

Merged
merged 5 commits into from
Jun 25, 2024

Conversation

shreyas-goenka
Copy link
Contributor

@shreyas-goenka shreyas-goenka commented Jun 24, 2024

Changes

There are four different treatments location metadata can receive in the convert.FromTyped method.

  1. Location metadata is retained for maps, structs and slices if the value is not nil
  2. Location metadata is lost for maps, structs and slices if the value is is nil
  3. Location metadata is retained if a scalar type (eg. bool, string etc) does not change.
  4. Location metadata is lost if the value for a scalar type changes.

This PR ensures that location metadata is not lost in any case; that is, it's always preserved.

For (2), this serves as a bug fix so that location information is not lost on conversion to and from typed for nil values of complex types (struct, slices, and maps).

For (4) this is a change in semantics. For primitive values modified in a typed mutator, any references to .Location() for computed primitive fields will now return associated YAML location metadata (if any) instead of an empty location.

While arguable, these semantics are OK since:

  1. Situations like these will be rare.
  2. Knowing the YAML location (if any) is better than not knowing the location at all. These locations are typically visible to the user in errors and warnings.

Tests

Unit tests

src = 1235
nv, err = FromTyped(src, ref)
require.NoError(t, err)
assert.Equal(t, dyn.NewValue(int64(1235), dyn.Location{File: "foo"}), nv)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FromTyped normalizes all integer values to int64

@shreyas-goenka shreyas-goenka marked this pull request as ready for review June 25, 2024 11:58
@pietern pietern changed the title Retain location metadata for values in dyn.FromTyped Retain location metadata for values in convert.FromTyped Jun 25, 2024
@shreyas-goenka shreyas-goenka added this pull request to the merge queue Jun 25, 2024
Merged via the queue into main with commit dac5f09 Jun 25, 2024
5 checks passed
@shreyas-goenka shreyas-goenka deleted the retain-location-in-from-typed branch June 25, 2024 13:46
pietern added a commit that referenced this pull request Jun 26, 2024
github-merge-queue bot pushed a commit that referenced this pull request Jun 26, 2024
…1528)

## Changes

This reverts commit dac5f09 (#1523).

Retaining the location for nil values means equality checks no longer
pass.

We need #1520 to be merged first.

## Tests

Integration test `TestAccPythonWheelTaskDeployAndRunWithWrapper`.
github-merge-queue bot pushed a commit that referenced this pull request Jun 27, 2024
…1520)

## Changes

This PR makes two changes:

1. In #1510 we'll be adding
multiple associated location metadata with a dyn.Value. The Go compiler
does not allow comparing structs if they contain slice values
(presumably due to multiple possible definitions for equality). In
anticipation for adding a `[]dyn.Location` type field to `dyn.Value`
this PR removes all direct comparisons of `dyn.Value` and instead relies
on the kind.

2. Retain location metadata for values in convert.FromTyped. The change
diff is exactly the same as #1523.
It's been combined with this PR because they both depend on each other
to prevent test failures (forming a test failure deadlock).

Go patch used:
```
@@
var x expression
@@
-x == dyn.InvalidValue
+x.Kind() == dyn.KindInvalid

@@
var x expression
@@
-x != dyn.InvalidValue
+x.Kind() != dyn.KindInvalid

@@
var x expression
@@
-x == dyn.NilValue
+x.Kind() == dyn.KindNil

@@
var x expression
@@
-x != dyn.NilValue
+x.Kind() != dyn.KindNil
```
 

## Tests
Unit tests and integration tests pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants