Skip to content

std::math: vector .pow() macro uses unqualified pow call, failing cross-module lookup #3512

Description

@ManuLinares

In lib/std/math/vector.c3:111, double[<*>].pow is defined as:

macro double[<*>] double[<*>].pow(double[<*>] x, exp) => pow(x, exp);

When inlined into a caller outside std::math, pow lacks a module prefix and causes a compile error.

Reproduction

module app;
import std;

fn void test()
{
    Vec3 v = { 1.0, 2.0, 3.0 };
    Vec3 asd = v.pow(2.0);
}

Compiler Output

$ c3c compile asd.c3
 73: macro float[<*>] float[<*>].fma(float[<*>] a, float[<*>] b, float[<*>] c) => $$fma(a, b, c);
 74: macro float[<*>] float[<*>].floor(float[<*>] x) => $$floor(x);
 75: macro float[<*>] float[<*>].nearbyint(float[<*>] x) => $$nearbyint(x);
 76: macro float[<*>] float[<*>].pow(float[<*>] x, exp) => pow(x, exp);
                                                           ^^^
/home/mb/scripts/c3c/lib/std/math/vector.c3:76:55: error: Macros from other modules must be prefixed with the module name, please use math::pow instead.

 4: fn void test()
 5: {
 6:     Vec3 v = { 1.0, 2.0, 3.0 };
 7:     Vec3 asd = v.pow(2.0);
                   ^^^^^^^^^^
/home/mb/scripts/c3c/asd.c3:7:16: note: Inlined from here.

To fix I've just prefixed pow with math:: in lib/std/math/vector.c3:

macro double[<*>] double[<*>].pow(double[<*>] x, exp) => math::pow(x, exp);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugSomething isn't workingFixed needs testingNeeds verification / testing that it now worksStdlibStandard library issue

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions