Skip to content

Positional parameters being placed after named parameters causes compilation error #2308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
youssef-attia opened this issue Jun 27, 2022 · 1 comment

Comments

@youssef-attia
Copy link

What happened?

I expected DartPad to accept positional parameters being placed in any order with named parameters but this is not the case.

Steps to reproduce problem

The minimum case to reproduce the error is:

import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const Text(key: Key('hello'), 'hello',);
  }
}

The errors that DartPad returns is:
"Error compiling to JavaScript:
/tmp/dartpadUTEEFM/lib/main.dart:10:18: Error: Constant evaluation error:
return const Text(key: Key('hello'), 'hello');
^
/tmp/dartpadUTEEFM/lib/main.dart:10:28: Context: The variable '(unnamed)' is not a constant, only constant expressions are allowed.
return const Text(key: Key('hello'), 'hello');"

The error can be fixed by changing the line: return const Text(key: Key('hello'), 'hello',); to return const Text('hello', key: Key('hello'),);

@johnpryan
Copy link
Contributor

This should be allowed now that this feature has shipped in 2.17: dart-lang/language#1072. Feel free to comment and we will reopen if you're still seeing an issue with this.

@johnpryan johnpryan closed this as not planned Won't fix, can't repro, duplicate, stale Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants