mirror of
https://github.com/carp-lang/Carp.git
synced 2024-08-15 16:20:40 +03:00
fix: mangle field names in setter templates (#1379)
* fix: mangle field names in setter templates This fixes a regression whereby the names of struct fields weren't mangled in calls to setters/mutators, resulting in invalid C code if the user happened to use reserved words in their struct field names such as "short" or a disallowed character like a dash. * test: check struct field name mangle regression This test ensures struct field names are mangled correctly in C output.
This commit is contained in:
parent
bd653ad6e6
commit
6f120b0e75
@ -288,7 +288,7 @@ setterGenerator = TG.mkTemplateGenerator tgen decl body deps
|
||||
body GeneratorArg {tenv, env, instanceT = (FuncTy [_, ty] _ _), value = (TC.StructField name _)} =
|
||||
multilineTemplate
|
||||
[ "$DECL {",
|
||||
memberDeletion tenv env (name, ty),
|
||||
memberDeletion tenv env (mangle name, ty),
|
||||
" p." ++ (mangle name) ++ " = newValue;",
|
||||
" return p;",
|
||||
"}\n"
|
||||
@ -319,7 +319,7 @@ mutatorGenerator = TG.mkTemplateGenerator tgen decl body deps
|
||||
body GeneratorArg {tenv, env, instanceT = (FuncTy [_, ty] _ _), value = (TC.StructField name _)} =
|
||||
multilineTemplate
|
||||
[ "$DECL {",
|
||||
memberRefDeletion tenv env (name, ty),
|
||||
memberRefDeletion tenv env (mangle name, ty),
|
||||
" pRef->" ++ mangle name ++ " = newValue;",
|
||||
"}\n"
|
||||
]
|
||||
|
@ -100,6 +100,13 @@
|
||||
(defn poly-nest-two [x] (Bar.Qux.init (Bar.Baz x)))
|
||||
(defn poly-nest-three [x] (PolyNest (Bar.Baz x)))
|
||||
|
||||
;; struct field names are mangled correctly (#1378)
|
||||
(deftype Mangled
|
||||
[short Int ;; c reserved word
|
||||
default-value String ;; invalid var name symbol (-)
|
||||
]
|
||||
)
|
||||
|
||||
(deftest test
|
||||
(assert-equal test
|
||||
1
|
||||
@ -160,4 +167,9 @@
|
||||
@(Bar.Baz.it (PolyNest.it &(poly-nest-three 2)))
|
||||
"test that polymorphic types in modules can be referred to using
|
||||
other types outside the module")
|
||||
(assert-equal test
|
||||
"bar"
|
||||
(Mangled.default-value &(Mangled.set-default-value (Mangled.init 0 @"foo")
|
||||
@"bar"))
|
||||
"struct field names are mangled correctly")
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user