From e26ce59797c3209ed64a661a3897c538662489d8 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 17 Apr 2026 16:18:39 -0500 Subject: [PATCH] for progmem --- esphome/cpp_generator.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/esphome/cpp_generator.py b/esphome/cpp_generator.py index 853025b4aa..a9dca970b6 100644 --- a/esphome/cpp_generator.py +++ b/esphome/cpp_generator.py @@ -477,7 +477,13 @@ def progmem_array(id_, rhs) -> "MockObj": rhs = safe_exp(rhs) obj = MockObj(id_, ".") assignment = ProgmemAssignmentExpression(id_.type, id_, rhs) - CORE.add(assignment) + # Emit at file scope, not inside setup(). setup() is split into + # per-component IIFE lambdas; a function-local static declared in one + # lambda is not visible to statements in sibling lambdas that + # reference the same shared table (e.g. two lights sharing a gamma + # lookup). File-scope static constexpr is semantically identical for + # read-only lookup tables. + CORE.add_global(assignment) CORE.register_variable(id_, obj) return obj @@ -486,7 +492,7 @@ def static_const_array(id_, rhs) -> "MockObj": rhs = safe_exp(rhs) obj = MockObj(id_, ".") assignment = StaticConstAssignmentExpression(id_.type, id_, rhs) - CORE.add(assignment) + CORE.add_global(assignment) CORE.register_variable(id_, obj) return obj