126
|
1 # HG changeset patch
|
|
2 # Parent 3741d7036c658afaa2944b1c0a144bac61b50930
|
|
3 rathaxes: fix cases where ${self} would be incorrectly resolved
|
|
4
|
|
5 diff --git a/rathaxes/compiler/passes/common/rtxResolve.inc.cws b/rathaxes/compiler/passes/common/rtxResolve.inc.cws
|
|
6 --- a/rathaxes/compiler/passes/common/rtxResolve.inc.cws
|
|
7 +++ b/rathaxes/compiler/passes/common/rtxResolve.inc.cws
|
|
8 @@ -696,7 +696,8 @@
|
|
9 case "target_expr":
|
|
10 // Is it a variable of a rathaxes type : check in type_map ?
|
|
11 if (isEmpty(local_node.prefix) && isEmpty(local_node.suffix)
|
|
12 - && existVariable(theChunk.type_map) && findElement(varName, theChunk.type_map))
|
|
13 + && ((existVariable(theChunk.type_map) && findElement(varName, theChunk.type_map))
|
|
14 + || varName == "self"))
|
|
15 {
|
|
16 traceLine("inject<\"__rtx_var__\">:<LOG> Injecting a type mapping (" + varName + ").");
|
|
17 // Create the resolverValues for the type resolution:
|
|
18 @@ -705,21 +706,35 @@
|
|
19 rtxNodeArgs(resVal);
|
|
20 local self;
|
|
21 local self_value;
|
|
22 + local self_type;
|
|
23 // First, try to retrieve value from previous resVals, otherwise build it from chunk
|
|
24 - if (rtxNodeArgs_GetArgByName(resolverValues, varName, self) == true)
|
|
25 + if (varName != "self")
|
|
26 {
|
|
27 - rtxNodeArg_getValue(self, self_value);
|
|
28 + if (rtxNodeArgs_GetArgByName(resolverValues, varName, self) == true)
|
|
29 + {
|
|
30 + rtxNodeArg_getValue(self, self_value);
|
|
31 + }
|
|
32 + else
|
|
33 + {
|
|
34 + clearVariable(self_value);
|
|
35 + cnormNode_TerminalId(self_value, varName);
|
|
36 + }
|
|
37 + rtxNodeArgs_AppendArg(resVal, "self", theChunk.type_map[varName], self_value);
|
|
38 + setall self_type = theChunk.type_map[varName];
|
|
39 }
|
|
40 else
|
|
41 {
|
|
42 - clearVariable(self_value);
|
|
43 - cnormNode_TerminalId(self_value, varName);
|
|
44 + // "self" as an identifier means that we're within some Type Template code.
|
|
45 + // Thus the actual value is the associated ResVal, and the type the template's type itself.
|
|
46 + if (rtxNodeArgs_GetArgByName(resolverValues, varName, self) == true)
|
|
47 + {
|
|
48 + rtxNodeArg_getValue(self, self_value);
|
|
49 + }
|
|
50 + rtxNodeArgs_AppendArg(resVal, "self", self.rtype, self_value);
|
|
51 + setall self_type = self.rtype;
|
|
52 }
|
|
53 - rtxNodeArgs_AppendArg(resVal, "self", theChunk.type_map[varName], self_value);
|
|
54
|
|
55 - local qTypeName = rtxRTypeName<theChunk.type_map[varName].type>(
|
|
56 - theChunk.type_map[varName]
|
|
57 - );
|
|
58 + local qTypeName = rtxRTypeName<self_type.type>(self_type);
|
|
59
|
|
60 local mapping;
|
|
61 local subParam;
|
|
62 @@ -727,8 +742,7 @@
|
|
63 local subidentifiers;
|
|
64 select n in subParam[].name { pushItem subidentifiers; subidentifiers#back = n; }
|
|
65
|
|
66 - if (type_map<qTypeName>(resVal, theChunk.type_map[varName],
|
|
67 - subidentifiers,
|
|
68 + if (type_map<qTypeName>(resVal, self_type, subidentifiers,
|
|
69 local_node, mapping, source_tree) == false)
|
|
70 {
|
|
71 traceLine(RED + "[Error] Could not resolve mapping of '"
|
|
72 @@ -761,7 +775,7 @@
|
|
73 // If there's a resval argument for it, then take the source type from there
|
|
74 // Otherwise, use the chunk's type_map.
|
|
75 if (rtxNodeArg_getRType(self, source_type) == false)
|
|
76 - { ref source_type = theChunk.type_map[varName]; }
|
|
77 + { ref source_type = self_type; }
|
|
78 rtxNodeArg_getRType(self, source_type);
|
|
79 }
|
|
80 else
|
|
81 @@ -769,7 +783,7 @@
|
|
82 // Now resolve the finaltype of the argument -> Retrieve actual param_type
|
|
83 removeVariable(subidentifiers#[0]); // Remove the first identifiers for the type resolution
|
|
84 local result_type;
|
|
85 - if (rtxTypingLookup_ResolveTypeFields(theChunk.type_map[varName], subidentifiers, theChunk, source_tree, source_type) == false)
|
|
86 + if (rtxTypingLookup_ResolveTypeFields(self_type, subidentifiers, theChunk, source_tree, source_type) == false)
|
|
87 {
|
|
88 error(RED + "[Error] Could not resolve type fields for variable '"
|
|
89 + subidentifiers#front + "'" + DEFAULT_COLOR);
|