From 329bf9587d5e89a3c2234f67b8e437645e6ed2fb Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 28 Nov 2024 21:36:24 -0500 Subject: [PATCH] Fix crash when inheriting from an undeclared methodmap. Bug: issue #1000 Test: new test case --- compiler/name-resolution.cpp | 4 ++-- tests/compile-only/fail-inherit-undeclared-methodmap.sp | 1 + tests/compile-only/fail-inherit-undeclared-methodmap.txt | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 tests/compile-only/fail-inherit-undeclared-methodmap.sp create mode 100644 tests/compile-only/fail-inherit-undeclared-methodmap.txt diff --git a/compiler/name-resolution.cpp b/compiler/name-resolution.cpp index ce63100c..8215ae7d 100644 --- a/compiler/name-resolution.cpp +++ b/compiler/name-resolution.cpp @@ -1138,8 +1138,8 @@ bool MethodmapDecl::Bind(SemaContext& sc) { auto& cc = sc.cc(); if (extends_) { - auto parent = FindSymbol(cc.globals(), extends_); - parent_ = MethodmapDecl::LookupMethodmap(parent); + if (auto parent = FindSymbol(cc.globals(), extends_)) + parent_ = MethodmapDecl::LookupMethodmap(parent); if (!parent_) report(pos_, 102) << "methodmap" << extends_; } diff --git a/tests/compile-only/fail-inherit-undeclared-methodmap.sp b/tests/compile-only/fail-inherit-undeclared-methodmap.sp new file mode 100644 index 00000000..42f0be4d --- /dev/null +++ b/tests/compile-only/fail-inherit-undeclared-methodmap.sp @@ -0,0 +1 @@ +methodmap A < B {} diff --git a/tests/compile-only/fail-inherit-undeclared-methodmap.txt b/tests/compile-only/fail-inherit-undeclared-methodmap.txt new file mode 100644 index 00000000..99d7845e --- /dev/null +++ b/tests/compile-only/fail-inherit-undeclared-methodmap.txt @@ -0,0 +1 @@ +(1) : error 102: cannot find methodmap B