Skip to content

Commit ce2553e

Browse files
committed
Detect type pun when fixing name~
1 parent 56c2759 commit ce2553e

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

jsrc/af.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,14 @@ static A jtfixa(J jt,A a,A w){A f,g,h,wf,x,y,z=w;V*v;fauxblock(fauxself); A aa;
124124
case CVDOT:
125125
R REFIXA(ai,JT(jt,implocref)[1]);
126126
case CTILDE:
127-
if(f&&NAME&AT(f)){
127+
if(f&&NAME&AT(f)){ // f is the name in name~
128128
RZ(y=sfn(0,f));
129129
if(all1(eps(box(y),(A)IAV0(aa)[1])))R w; // break out of loop if recursive name lookup
130130
ASSERT(AN((A)IAV0(aa)[1])<248,EVLIMIT); // error if too many names in expansion
131131
// recursion check finished. Now replace the name with its value
132132
if(x=symbrdlock(f)){ // locked returns a ref to the same name
133+
// since the name is supposed to be executable, we have to guard against a type pun on the name
134+
ASSERT(PARTOFSPEECHEQACV(AT(w),AT(x)),EVDOMAIN); // make sure its part of speech has not changed since the name was parsed
133135
if(unlikely(AFLAG(x)&AFRO))R w; // If name has readonly value (like cocurrent), leave it as a reference
134136
// if this is an implicit locative, we have to switch the environment before we recur on the name for subsequent lookups
135137
// The value we get from the lookup must be interpreted in the environment of the higher level

jsrc/jtype.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ typedef I SI;
565565
#define TYPESGT(x,y) ((UI)(x)>(UI)(y)) // type x > type y
566566

567567
#define PARTOFSPEECHEQ(x,y) (((((x)|(LPAR&-((x)&NOUN)))^((y)|(LPAR&-((y)&NOUN))))&LPAR+CONJ+VERB+ADV)==0) // using LPAR to hold NOUN status, verify parts-of-speech the same
568-
#define PARTOFSPEECHEQACV(x,y) ((((x)^(y))&CONJ+VERB+ADV)==0) // verify known-nonnoun parts-of-speech the same
568+
#define PARTOFSPEECHEQACV(x,y) ((((x)^(y))&CONJ+VERB+ADV)==0) // verify known-nonnoun parts-of-speech the same - enough is either value known to be ACV
569569

570570
// Utility: keep the lowest 1 only
571571
#define LOWESTBIT(x) ((x)&-(x))

test/g310r.ijs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,11 @@ assert. 101 -: 100 [&.c 0
275275
)
276276
f ''
277277

278+
NB. verify puns detected when replacing implicit locatives
279+
'domain error' -: ". etx '1 {{ 0 + v. }} 2 ]3'
280+
'domain error' -: ". etx '+ {{ 0 + v. }} 2 ]3'
281+
_3 -:+ {{ 0 + v. }} - ]3
282+
278283
4!:55 ;:'a aa q a_z_ c_z_ d_yyy_ d_xxx_ g_z_ j j_xxx_ dou F f F1 f1 F2 f2 G g G1 g1 G2 g2 nameinxxx_xxx_ nln nm nn sum v'
279284
(271828) 18!:55 ;:'xxx yyy'
280285

0 commit comments

Comments
 (0)