From a2e4d0a565a8e756f36177003a51e224aca238b9 Mon Sep 17 00:00:00 2001 From: lemon Date: Fri, 5 Aug 2022 19:56:09 +0200 Subject: . operator on pointers --- bootstrap/parse.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'bootstrap/parse.c') diff --git a/bootstrap/parse.c b/bootstrap/parse.c index 32cd202..9c6f5a8 100644 --- a/bootstrap/parse.c +++ b/bootstrap/parse.c @@ -1000,9 +1000,12 @@ pexpostfix(struct parser *P) { }; } else if (lexmatch(P, &tok, '.')) { const char *fnam = (tok = lexexpect(P, TKident)).str; - if (ex.ty->t == TYstruct || ex.ty->t == TYunion) { - int idx = structfldnam2idx(ex.ty, fnam); - struct aggfield *fld = &ex.ty->agg.flds.d[idx]; + const struct type *ty = ex.ty; + if (ty->t == TYptr) + ty = ty->child; + if (ty->t == TYstruct || ty->t == TYunion) { + int idx = structfldnam2idx(ty, fnam); + struct aggfield *fld = &ty->agg.flds.d[idx]; if (idx < 0) fatal(P, tok.span, "%t has no such field `%s'", ex.ty, fnam); @@ -1012,7 +1015,7 @@ pexpostfix(struct parser *P) { ex.ty = fld->ty; ex.get.fld = fnam; } else { - fatal(P, tok.span, "cannot acces `%s': left-hand-side is not an aggregate (%t)", + fatal(P, tok.span, "cannot access `%s': left-hand-side is not an aggregate (%t)", fnam, ex.ty); } } else { -- cgit v1.2.3