v icon indicating copy to clipboard operation
v copied to clipboard

Instantiating a `type` causes "symbol(s) not found" compilation error

Open hraftery opened this issue 2 years ago • 0 comments

Describe the bug

Have been happily compiling and testing a lot over the last few days. Just went back to an old source file to try the type feature. I defined type RobotStorage = []string and replaced my existing uses of []string. When I tried to compile I got something like "unknown type in array initialisation" on return [] where previously that had worked to return a []string. So I tried some other options like return RobotStorage{} but when that didn't work just tried return []string{}. At that point the compiler error appeared.

Expected Behavior

Either no errors, or an error about how I'm trying to instantiate a new RobotStorage on line 12.

Current Behavior

% v robot-name.v
==================
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
...
==================
(Use `v -cg` to print the entire error message)

builder error: 
==================
C error. This should never happen.

This is a compiler bug, please report it using `v bug file.v`.

Reproduction Steps

Hmm, I thought this was what v bug robot-name.v was going to do. Um... here's the full file and all I did was run v robot-name.v.

module main

import rand

struct Robot {
mut:
	name string
}
type RobotStorage = []string

fn create_robot_storage() RobotStorage {
	return []string{}
}

fn create_robot(mut robots RobotStorage) Robot {
	n := generate_random_unique_name(robots)
	robots << n
	return Robot { n }
}

fn (mut r Robot) reset(mut robots RobotStorage) {
	n := generate_random_unique_name(robots)
	robots[robots.index(r.name)] = n
	r.name = n
}

fn generate_random_name() string {
	chars  := rand.string(2).to_upper()
	digits := rand.intn(1000) or { panic("Should only happen if 1000 is <= 0")}
	return "${chars}${digits:03}"
}

fn generate_random_unique_name(robots RobotStorage) string {
	for true {
		n := generate_random_name()
		if n !in robots { return n }
	}
	return "" //unreachable, but compiler needs it
}

fn main() {
	println(generate_random_name())
}

Possible Solution

The error message sounds like an installation issue, but I've had no installation issues. So I can only guess it's related to my introduction of type.

Additional Information/Context

I know the importance of this, but I really have nothing more to add - if the exact file and compiler produces the error then that's all the context you need I suppose. If they don't then maybe it's something fleeting.

V version

V 0.3.3 7de3485, timestamp: 2023-03-05 11:41:19 +0100

Environment details (OS name and version, etc.)

OS: macos, macOS, 13.2.1, 22D68 Processor: 10 cpus, 64bit, little endian, Apple M1 Max CC version: Apple clang version 14.0.0 (clang-1400.0.29.202)

getwd: /Users/liteyear/Exercism/vlang/robot-name vmodules: /Users/liteyear/.vmodules vroot: /Users/liteyear/Programming/v vexe: /Users/liteyear/Programming/v/v vexe mtime: 2023-03-06 05:45:43 is vroot writable: true is vmodules writable: true V full version: V 0.3.3 9c9adb1.7de3485

Git version: git version 2.37.1 (Apple Git-137.1) Git vroot status: weekly.2023.09-35-g7de3485b .git/config present: true thirdparty/tcc status: thirdparty-macos-arm64 a668e5a0

hraftery avatar Mar 06 '23 05:03 hraftery