diff --git a/compiler/noirc_frontend/src/hir_def/types.rs b/compiler/noirc_frontend/src/hir_def/types.rs index fe347661195..8fca878a6d7 100644 --- a/compiler/noirc_frontend/src/hir_def/types.rs +++ b/compiler/noirc_frontend/src/hir_def/types.rs @@ -1299,7 +1299,7 @@ impl Type { } Type::Array(length, element) => { - self.array_or_string_len_is_not_zero() + (Self::should_allow_zero_sized_input() || self.array_or_string_len_is_not_zero()) && length.is_valid_for_program_input() && element.is_valid_for_program_input() } @@ -1322,6 +1322,14 @@ impl Type { } } + /// Check if it is okay to allow for zero-sized input (e..g zero-sized arrays) to a program. + /// This behavior is not well defined and is banned by default. + /// However, this ban is a breaking change for some dependent projects so this override + /// is provided until those projects migrate away from using zero-sized array input (e.g. ). + fn should_allow_zero_sized_input() -> bool { + std::env::var("ALLOW_EMPTY_INPUT").ok().map(|v| v == "1" || v == "true").unwrap_or_default() + } + /// Empty arrays and strings (which are arrays under the hood) are disallowed /// as input to program entry points. ///