1+ # -----------------------------------------------------------------------
2+ # This file is part of MoonScript
3+ #
4+ # MoonSript is free software: you can redistribute it and/or modify
5+ # it under the terms of the GNU General Public License as published by
6+ # the Free Software Foundation, either version 3 of the License, or
7+ # (at your option) any later version.
8+ #
9+ # MoonSript is distributed in the hope that it will be useful,
10+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ # GNU General Public License for more details.
13+ #
14+ # You should have received a copy of the GNU General Public License
15+ # along with MoonSript. If not, see <https://www.gnu.org/licenses/>.
16+ #
17+ # Copyright (C) 2025 Krisna Pranav, MoonScript Developers
18+ # -----------------------------------------------------------------------
19+
20+ module MoonScript
21+ class TypeChecker
22+ def check (node : Ast ::Emit ) : Checkable
23+ error! :emit_no_signal do
24+ snippet " Emit cannot be used outside of signals:" , node
25+ end unless signal = node.signal
26+
27+ type =
28+ resolve node.expression
29+
30+ signal_type =
31+ resolve signal.type
32+
33+ error! :emit_type_mismatch do
34+ snippet " The emitted values type is different from the signals type:" ,
35+ signal_type
36+
37+ snippet " The type of the emitted value is:" , type
38+ end unless Comparer .compare(type , signal_type)
39+
40+ VOID
41+ end
42+ end
43+ end
0 commit comments