From c2cac772e3350a24433c4306f712352a5c8a7975 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Tue, 18 May 2021 23:37:52 +0200 Subject: [PATCH] validate string interning --- compilerAst/src/prog8/ast/AstToplevel.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/compilerAst/src/prog8/ast/AstToplevel.kt b/compilerAst/src/prog8/ast/AstToplevel.kt index 64db46607..77a41c01a 100644 --- a/compilerAst/src/prog8/ast/AstToplevel.kt +++ b/compilerAst/src/prog8/ast/AstToplevel.kt @@ -282,6 +282,13 @@ class Program(val name: String, } fun internString(string: StringLiteralValue, dedup: Boolean): List { + // Move a string literal into the internal, deduplicated, string pool + // replace it with a variable declaration that points to the entry in the pool. + + if(string.parent is VarDecl) { + // deduplication can only be performed safely for known-const strings (=string literals OUTSIDE OF A VARDECL)! + throw FatalAstException("cannot intern a string literal that's part of a vardecl") + } fun getScopedName(string: StringLiteralValue): List { val internedStringsBlock = modules