context.getDefaultAssignmentScope() is now being used too often

Description

context.getDefaultAssignmentScope() was only supposed to be used as the default scope argument to the scopeFindNearby() method when assigning a variable that may not exist or safely looking up an unscope variable on the left had hand side of the elvis operator or safe navigation operator. The goal was never to replace ALL instance of variablesScope with this.

Now code such as

variables.foo

is transpiling to

context.getDefaultAssignmentScope().dereference(Key.of("foo"), false)

but this is not correct. In the event that the BoxLang code has an explicit scope in the code, then the transpiled Java code should use

content.getScopeNearby( WhateverScope.name )

in order to get that explicit scope.

blocks

Activity

Show:

Brad WoodNovember 6, 2023 at 10:36 PM

I have updated a bunch of test which had incorrect expected values for transpiled java source, mostly related to accessing explicitly scoped variables. Many of these tests I had already reviewed a few weeks back to ensure they had the correct expected values, but they were recently changed to have an incorrection assertion, which made them pass when they should have been failing!

For example, in this commit, I set safe=true in the assertion and put a comment explaining why it needed to be true
https://github.com/ortus-solutions-private/boxlang/commit/de54dca10d77b7eb8068f146ffbfe1157edc3529#diff-b1d0e2667e9fa7a7f2[…]8ab089b0ff85e34b443R247

but 3 days ago, my changes were reverted and the assertion was switched to match the current output of the transpiler so the test would pass
https://github.com/ortus-solutions-private/boxlang/commit/19e3ab785e4f83cbe09ba114beb240441a458b05#diff-b1d0e2667e9fa7a7f2[…]8ab089b0ff85e34b443R251

But the original assertion was correct and the test should not be passing. If you think any of the expected values are incorrect in the test assertions, please ask first so we can discuss before we change the tests again.

Brad WoodNovember 6, 2023 at 8:55 PM

Note, it’s ok to use a variablesScope reference if the scope reference has already been obtained above, but keep in mind not all scopes exist in all contexts.

Fixed
Pinned fields
Click on the next to a field label to start pinning.

Details

Assignee

Reporter

Labels

Components

Priority

Sentry

Created November 6, 2023 at 8:52 PM
Updated November 8, 2023 at 5:36 AM
Resolved November 8, 2023 at 5:36 AM

Flag notifications