Fix BANK(@) discrepancy within LOAD blocks (#2149)

RGBASM and RGBLINK disagreed on which section to consider `@` to be in;
we have decided that the latter is correct.

The `assume` change is known to be suspicious; for more discussion, see
https://github.com/gbdev/rgbds/pull/2149#discussion_r4106902830
This commit is contained in:
Rangi authored and GitHub committed 2026-09-25 19:18:52 +02:00
1 parent dc701294f8
commit 646cb05faf
6 files changed
+35 -10

No files matched your search

+1 -1
View File
@@ -148,7 +148,7 @@ static void initPatch(Patch &patch, uint32_t type, Expression const &expr, uint3
void out_CreatePatch(uint32_t type, Expression const &expr, uint32_t ofs, uint32_t pcShift) {
// Add the patch to the list
assume(sect_GetOutputBank().has_value());
assume(sect_GetSymbolSection() != nullptr);
Patch &patch = *sect_AddOutputPatch();
initPatch(patch, type, expr, ofs);
+3 -3
View File
@@ -83,14 +83,14 @@ void Expression::makeBankSymbol(InternedStr symName) {
assume(rpn.empty());
if (Symbol const *sym = sym_FindScopedSymbol(symName); sym_IsPC(sym)) {
// The @ symbol is treated differently.
if (std::optional<uint32_t> outputBank = sect_GetOutputBank(); !outputBank) {
if (Section *section = sect_GetSymbolSection(); !section) {
error("PC has no bank outside of a section");
data = 1;
} else if (*outputBank == UINT32_MAX) {
} else if (section->bank == UINT32_MAX) {
data = "Current section's bank is not known";
rpn.emplace_back(RPN_BANK_SELF);
} else {
data = static_cast<int32_t>(*outputBank);
data = static_cast<int32_t>(section->bank);
}
} else if (sym && !sym->isLabel()) {
error("`BANK` argument must be a label");
-4
View File
@@ -644,10 +644,6 @@ uint32_t sect_GetOutputOffset() {
return curOffset + loadOffset;
}
std::optional<uint32_t> sect_GetOutputBank() {
return currentSection ? std::optional<uint32_t>(currentSection->bank) : std::nullopt;
}
Patch *sect_AddOutputPatch() {
return currentSection ? &currentSection->patches.emplace_front() : nullptr;
}