Skip to content

C compile error in option field in a struct #23446

Description

@penguindark

Describe the bug

Using an option field with map in structs generate C compiler error

Reproduction Steps

compile:

// module comconf

import os

struct BatchCommonConfig {
	ingestor_db map[string]string
	working_db map[string]string
	remote_db map[string]string
	ready_db ?map[string]string
	mut: client_db ?map[string]string
}

fn main(){

	new_era_db_env := os.getenv_opt('NEW_ERA_DB_ENV') or {'local_container'}
	mut config := match new_era_db_env {
		'local_container' {BatchCommonConfig{

			ingestor_db: {
				'username': 'username_data',
				'password': 'psw_data',
				'hostname': 'postgres_wh',
				'database': 'ingestor_db_test',
				'port': '5432'
        	}

			working_db: {
				'username': 'username_data',
				'password': 'psw_data',
				'hostname': 'postgres_wh',
				'database': 'working_db_test',
				'port': '5432'
			}

			remote_db: {
				'username': 'username_data',
				'password': 'psw_data',
				'hostname': 'postgres_wh',
				'database': 'remote_db_test',
				'port': '5432'
			}
			client_db: {
				'test' : 'test'
			}

		}}
		'local' {BatchCommonConfig{

			ingestor_db: {
				'username': 'postgres',
				'password': 'postgres',
				'hostname': '127.0.0.1',
				'database': 'ingestor_db_test',
				'port': '5432'
        	}

			working_db: {
				'username': 'postgres',
				'password': 'postgres',
				'hostname': '127.0.0.1',
				'database': 'working_db_test',
				'port': '5432'
			}

			remote_db: {
				'username': 'postgres',
				'password': 'postgres',
				'hostname': '127.0.0.1',
				'database': 'remote_db_test',
				'port': '5432'
			}

			ready_db: {
				'username': 'postgres',
				'password': 'postgres',
				'hostname': '127.0.0.1',
				'database': 'acme_db_test',
				'port': '5432'
			}
			
			client_db: {
				'username': 'postgres',
				'password': 'postgres',
				'hostname': '127.0.0.1',
				'database': 'remote_db_test_remote',
				'port': '5432'
			}

		}}
		else {panic('what is the target db?')} 
	}

	b := 'print test ${config.client_db['test'] or {'test'}}' 
	println(b)

}

Expected Behavior

The print of the field or its option

Current Behavior

cc: C:/Users/dario/AppData/Local/Temp/v_0/marco.01JHDMTGSCW33PCJ7ETMJQF2CH.tmp.c:4628: warning: implicit declaration of function 'tcc_backtrace'
cc: C:/Users/dario/AppData/Local/Temp/v_0/marco.01JHDMTGSCW33PCJ7ETMJQF2CH.tmp.c:7722: error: cannot convert 'struct _option_Map_string_string' to 'int'
... (the original output was 3 lines long, and was truncated to 2 lines)
=================================================================
(You can pass `-cg`, or `-show-c-output` as well, to print all the C error messages).
builder error:
==================
C error found. It should never happen, when compiling pure V code.
This is a V compiler bug, please report it using `v bug file.v`,
or goto https://github.com/vlang/v/issues/new/choose .
You can also use #help on Discord: https://discord.gg/vlang .

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.9 d2b30df

Environment details (OS name and version, etc.)

Ubuntu 22, Windows 10

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugThis tag is applied to issues which reports bugs.Status: ConfirmedThis bug has been confirmed to be valid by a contributor.Unit: CompilerBugs/feature requests, that are related to the V compiler in general.Unit: cgenBugs/feature requests, that are related to the default C generating backend.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions