lang: types, core: Skip over invalid functions

It's not clear how best to support complex functions with struct fields
in templates at the moment. Skip these for now.
This commit is contained in:
James Shubin
2024-03-15 21:19:29 -04:00
parent 719c56e754
commit a8b945e36e
3 changed files with 44 additions and 5 deletions

View File

@@ -899,6 +899,11 @@ func (obj *Type) Reflect() reflect.Type {
if t == nil {
panic("malformed struct field")
}
if strings.Title(k) != k { // is exported?
//k = strings.Title(k) // TODO: is this helpful?
// reflect.StructOf would panic on anything unexported
panic(fmt.Sprintf("struct has unexported field: %s", k))
}
fields = append(fields, reflect.StructField{
Name: k, // struct field name

View File

@@ -1502,3 +1502,25 @@ func TestTypeOf0(t *testing.T) {
// TODO: implement testing of the TypeOf function
// TODO: implement testing TypeOf for struct field name mappings
}
func TestReflect0(t *testing.T) {
mustPanic := func() (reterr error) {
defer func() {
// catch unhandled panics
if r := recover(); r != nil {
reterr = fmt.Errorf("panic: %+v", r)
}
}()
// It's unclear if we want this behaviour forever, but it is the
// current behaviour, and I'd at least like to know if it
// changes so we can understand where (if at all) it's required.
typ := NewType("struct{field1 str}")
_ = typ.Reflect()
return nil
}
if err := mustPanic(); err == nil {
t.Errorf("expected panic, got nil")
}
}