From cded48ac3d6ef23942e6cf03eb4df26f34710c15 Mon Sep 17 00:00:00 2001 From: Graham Nelson Date: Thu, 26 May 2022 21:44:16 +0100 Subject: [PATCH] Fix for Jira bug I7-1806 --- docs/knowledge-module/2-nv.html | 42 ++++++++++++++++--- inform7/Figures/timings-diagnostics.txt | 12 +++--- .../Test Problems/PM_IndefiniteVariable2.txt | 5 +++ .../_Results_Ideal/PM_IndefiniteVariable2.txt | 13 ++++++ .../Chapter 2/Nonlocal Variables.w | 29 ++++++++++++- 5 files changed, 87 insertions(+), 14 deletions(-) create mode 100644 inform7/Tests/Test Problems/PM_IndefiniteVariable2.txt create mode 100644 inform7/Tests/Test Problems/_Results_Ideal/PM_IndefiniteVariable2.txt diff --git a/docs/knowledge-module/2-nv.html b/docs/knowledge-module/2-nv.html index 8fa2211e1..b548033ab 100644 --- a/docs/knowledge-module/2-nv.html +++ b/docs/knowledge-module/2-nv.html @@ -172,8 +172,12 @@ only match globals, since variables of lesser scope are not in the lexicon. nonlocal_variable *NonlocalVariables::new(wording W, kind *K, shared_variable *shv) { if (K == NULL) internal_error("created variable without kind"); - if (Kinds::Behaviour::definite(K) == FALSE) - Issue problem message for an indefinite variable4.1; + if (Kinds::Behaviour::definite(K) == FALSE) { + if (Kinds::get_construct(K) == CON_phrase) + Issue problem message for a phrase used before its kind is known4.2 + else + Issue problem message for an indefinite variable4.1; + } nonlocal_variable *nlv = CREATE(nonlocal_variable); latest_nonlocal_variable = nlv; @@ -189,7 +193,7 @@ only match globals, since variables of lesser scope are not in the lexicon. nlv->as_subject = VariableSubjects::new(nlv); nlv->compilation_data = RTVariables::new_compilation_data(); - Notice a few special variables4.4; + Notice a few special variables4.5; PluginCalls::new_variable_notify(nlv); LOGIF(VARIABLE_CREATIONS, "Created nonlocal variable: $Z\n", nlv); @@ -213,7 +217,33 @@ only match globals, since variables of lesser scope are not in the lexicon. Problems::issue_problem_end(); -

§4.2. Four oddball cases have special behaviour: +

§4.2. This typically arises for timing reasons. At the time the variable has to be +created, and given a kind, the kind of the initial value has not been fully +determined. So K here will be something like phrase value -> value. If this +case arose often enough it might be worth refactoring everything, but it's +rarely occurring and has an easy workaround. So we will just give a fairly +helpful problem message: +

+ +

Issue problem message for a phrase used before its kind is known4.2 = +

+ +
+    LOG("W = %W, Domain = %u\n", W, K);
+    Problems::quote_wording(1, W);
+    StandardProblems::handmade_problem(Task::syntax_tree(),
+        _p_(PM_IndefiniteVariable2));
+    Problems::issue_problem_segment(
+        "I am unable to create '%1', because the text was too vague about what "
+        "its kind should be - I can see it's a phrase, but not what kind of phrase. "
+        "(You may be able to fix this by declaring the kind directly first. For "
+        "example, rather than 'The magic word is initially my deluxe phrase.', "
+        "something like 'The magic word is a phrase nothing -> nothing variable. "
+        "The magic word is initially my deluxe phrase.')");
+    Problems::issue_problem_end();
+
+ +

§4.3. Four oddball cases have special behaviour: