Repository navigation
Description
What happened?
EncodableInspector.safeAccessed hops from an accessor to the field it accesses, because that is where a class val keeps its annotations. A trait val or var has no backing field, so the hop lands on NoSymbol and drops the marker: with no field to carry them, a trait member's annotations stay on its accessor, whatever their @Target. The argument is then classified as a plain literal:
trait Labels { @EncodableStringAnnotation val title: String; def snippet = pyb"print($title)" } // title = "hello"
Before: PyLiteralStringRenderer -> print(hello)
After: EncodableStringRenderer -> print(self.decode_python_template('aGVsbG8='))
It fails open. There is no compile error and no runtime check: BoundaryValidator.validateCompileTime only runs for arguments the inspector classified Encodable, so an unsafe splice of the same value goes uncaught too. The same member as a concrete val on a class is encoded correctly.
Nothing in production declares a marked trait member today — the only modifier-position use of the marker outside pybuilder is Attribute.getName(), a Java method rather than an accessor — so this is latent, but it is the direction that puts a UI-supplied string into generated Python unencoded. The same safeAccessed is on release/v1.2 and release/v1.3. First noted while covering the inspector in #7862.
An abstract class's abstract val is a different shape: there scalac keeps the marker on neither the accessor nor a field, so the macro cannot see it at all, and the type-position form (val title: String @EncodableStringAnnotation, which the EncodableString alias expands to) is the one that works.
How to reproduce?
pyb expands to a private[amber] factory, so the source has to live under org.apache.texera.amber:
package org.apache.texera.amber.repro
import org.apache.texera.amber.pybuilder.{EncodableStringAnnotation, PythonTemplateBuilder}
import org.apache.texera.amber.pybuilder.PythonTemplateBuilder._
trait Labels {
@EncodableStringAnnotation val title: String
def snippet: PythonTemplateBuilder = pyb"print($title)"
}
object Repro extends App {
val labels = new Labels { val title = "hello" }
println(labels.snippet.encode) // print(hello)
println(labels.snippet.containsEncodableString) // false
}With class Labels { @EncodableStringAnnotation val title: String = "hello"; ... } instead, the same two lines print print(self.decode_python_template('aGVsbG8=')) and true.
Version/Branch
1.4.0-incubating-SNAPSHOT (main)
Commit Hash (Optional)
What browsers are you seeing the problem on?
No response
Relevant log output
No response
Activity
anishshiva7 commentedon Nov 24, 2026
/take